Intuit Anywhere script reloading jQuery

爱⌒轻易说出口 提交于 2019-12-11 03:27:36

问题


Our application loads jQuery 1.10.2 and then loads https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js from Intuit. The anywhere script is adding <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script> to the head and reloading jQuery.

This is wiping the namespace and wrecking much of our code. Shouldn't the script see that jQuery is already loaded? How do we prevent jquery from being reloaded?

Thanks, Forrest


回答1:


EDIT:

The problem seems to be that window.jQuery.fn.jquery < "1.4.2" returns false as '1.10.2' < '1.4.2' will also return false. It is because javascript will see it as 1.1.2 < 1.4.2. Another option is to remove the || window.jQuery.fn.jquery < "1.4.2"


If you are sure that you are including jQuery just change the part of the code where it appends the script tag.

At the bottom of the script. Change

// function that starts it all. timeout is 0
(function() {
    // these are the domains whose js files we're going to look at
    // intuit.ipp.ourDomain = /(.intuit.com).*?#(.*)/;
    intuit.ipp.ourDomain = /intuit.com$/;
    if(window.jQuery === undefined || window.jQuery.fn.jquery < "1.4.2") {
        // minimum version 1.4.2
        var script_tag = document.createElement('script');
        script_tag.setAttribute("type","text/javascript");
        script_tag.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js");
        script_tag.onload = function () {
            if(window.jQuery) {
                intuit.ipp.jQuery = window.jQuery.noConflict(true);
                intuit.ipp.anywhere.windowLoad();
            }
        };
        script_tag.onreadystatechange = function () { // Same thing but for IE
            if (this.readyState == 'complete' || this.readyState == 'loaded') {
                script_tag.onload();
            }
        };

        // Try to find the head, otherwise default to the documentElement
        (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);

    } else {
        // we do have jquery
        intuit.ipp.jQuery = window.jQuery;
        intuit.ipp.anywhere.windowLoad();
    }
})();

To

// function that starts it all. timeout is 0
(function () {
    // these are the domains whose js files we're going to look at
    // intuit.ipp.ourDomain = /(.intuit.com).*?#(.*)/;
    intuit.ipp.ourDomain = /intuit.com$/;
    // we do have jquery
    intuit.ipp.jQuery = window.jQuery;
    intuit.ipp.anywhere.windowLoad();
})();



回答2:


The solution given by Spokey is partially correct.

In order to serve the Anywhere script locally, you also need to make some modifications to the code for allowing the domain to point to the Intuit site. This way, the CSS and the Application links on the Blue Dot Menu are redirected correctly to Intuit's domain.

(Note: Updating the intuit.ipp.ourDomain variable won't work as stated above.)

Here is what I modified:

Lines 20-40 contains:

windowLoad  : function() {
    intuit.ipp.jQuery(document).ready(function () {
        intuit.ipp.jQuery('script').each(function (){
            // check if this script file is from our domain
            if (!this.src) {
                return;
            }
            var jsSrc = this.src;
            var jsSrcParts = jsSrc.replace(/http[s]?:\/\//, '').split('/');
            var qs = intuit.ipp.ourDomain.exec(jsSrcParts[0]);
            if(!qs) {
                qs = document.domain.match(intuit.ipp.ourDomain);
            }
            if (!qs || !jsSrcParts[jsSrcParts.length - 1].match('intuit.ipp.anywhere') || !jsSrc.match(/:\/\/(.[^/]+)/)) {
                return;
            }
            // get ipp's domain
            intuit.ipp.anywhere.serviceHost = jsSrc.match(/:\/\/(.[^/]+)/)[1];

I replaced with these:

windowLoad  : function() {
    intuit.ipp.jQuery(document).ready(function () {
        intuit.ipp.jQuery('script').each(function (){
            // check if this script file is from our domain
            if (!this.src) {
                return;
            }
            var jsSrc = this.src;
            var jsSrcParts = jsSrc.replace(/http[s]?:\/\//, '').split('/');
            var qs = intuit.ipp.ourDomain.exec(jsSrcParts[0]);
            // if(!qs) {
            //  qs = document.domain.match(intuit.ipp.ourDomain);
            // }
            if (!jsSrcParts[jsSrcParts.length - 1].match('intuit.ipp.anywhere') || !jsSrc.match(/:\/\/(.[^/]+)/)) {
                return;
            }
            // get ipp's domain
            //intuit.ipp.anywhere.serviceHost = jsSrc.match(/:\/\/(.[^/]+)/)[1];
            intuit.ipp.anywhere.serviceHost = "appcenter.intuit.com";


来源:https://stackoverflow.com/questions/17791357/intuit-anywhere-script-reloading-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!