Techek
Techek

Reputation: 475

Using jQuery in CRM Dynamics 365 webresource in popup-window

In my CRM Dynamics 365 solution I have a form with an embedded webresource A. This webresource A opens another webresource B in a popup-window using window.open. The opening could of course also be done using Xrm.Utility.openWebResource.

I would like to utilize jQuery in webresource B. I am aware that CRM itself loads jQuery in some version, which is easy to spot when monitoring network requests and filtering for jquery.

The problem is that the webresource B doesn't have "access" to the jQuery or $-variable. The question is what you would recommend to do in order to use jQuery. I've prioritized a list of some possible solutions:

  1. Load a webresource with an independent version of jQuery
  2. An option I haven't thought of
  3. Load it from a CDN
  4. Look for all loaded scripts with jQuery and pass the URL to webresource B so it can load it by itself (almost a hack)
  5. Avoid jQuery, use vanilla JS

UPDATE: The main reason for using jQuery was to easily resize an iframe (with random contents) embedded in popup-window which displayed webresource B according to the dimensions of the popup-window.

I decided to lose jQuery altogether and use CSS instead. My solution became this which work nicely in Google Chrome, Windows Edge and Internet Explorer 11:

#externalframe {
    width: 100%;
    height: 100%;
    display: block;
    float: left;
}

Upvotes: 1

Views: 1174

Answers (2)

Yaqub Ahmad
Yaqub Ahmad

Reputation: 27659

If you can access jsquery in webresourceA then it means that the jquery already exists (as a webresource) in CRM. Find the url(path) of jquery and add it as a reference to the webresourceB and that's it.

Upvotes: 1

I recommend Encapsulation & Namespacing of jQuery technique.

if you would like to quickly get access to the jQuery libraries in Dynamics CRM, you can install the SparkelXrm managed solution and include the web resource named ‘sparkle_/js/SparkleXrmUI_Dependancies.js’ – this is a single library that has both jQuery, jQueryUI as well as a few other goodies such as Knockout JS!

Upvotes: 1

Related Questions