Question

I had a customer come to me today with the issue that our JQuery file is interfering with another vendors product.

The scenario is MS CRM 2011. We have some buttons in the ribbon that require JQuery. Unfortunately this ends up causing our script files to be everywhere the ribbon is and not just where we need them.

The other vendor also uses JQuery on their entities. Because we have our scripts in the ribbon though, both sets of scripts are present for the other vendor and there's a version mismatch. It's causing an error for the other vendor.

We're clearly in the wrong here but I don't know what to do to fix it. We already have an alias in place but that only seems to work for our own scripts so we don't end up using someone elses version of JQuery. The other vendor is going to alias their version of JQuery to solve the problem but I'd rather not cause this issue for anyone else in the future.

Is there any way I can create the alias in the actual JQuery file as opposed to just our own scripts? Essentially I want to prevent anyone else from using my JQuery file accidentally.

EDIT1: To clarify, we have JQuery included as a web resource in MS CRM and have it included on the button as an additional library. We do this the way it's described here: http://rajeevpentyala.wordpress.com/2012/05/23/loading-dependent-jscript-libraries-in-ribbon-buttons-execution-crm-2011/ There isn't the traditional include line thus I was hoping there was something I could do in the actual JQuery file itself to restrict it.

Was it helpful?

Solution

The best way to solve it would be to not use a 3rd party library with your code. However, since that likely isn't an option, here's another way to solve it:

<script src="jquery.js"></script>
<script src="yourexternaljs.js"></script>

yourexternaljs.js:

(function($){
    // you are free to use $ inside of this area without conflicting with anyone elses code.
    $(document).ready(function(){
        alert("dom is ready.");
    })
})(jQuery.noConflict(true));

Per your edit, yes, you could go into jquery.js and change all references to window.jQuery and window.$ to whatever you want, it should only be in there 2-4 times.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top