Intuit Anywhere脚本重新加载jQuery

我们的应用程序加载jQuery 1.10.2,然后从Intuit加载https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js 。 随处脚本将到头部重新加载jQuery。

这就是擦除命名空间并破坏我们的大部分代码。 脚本不应该看到jQuery已经加载了吗? 我们如何防止重新加载jquery?

谢谢,福雷斯特

编辑:

问题似乎是window.jQuery.fn.jquery < "1.4.2"返回false,因为'1.10.2' < '1.4.2'也将返回false。 这是因为javascript会将其视为1.1.2 < 1.4.2 。 另一种选择是删除|| window.jQuery.fn.jquery < "1.4.2" || window.jQuery.fn.jquery < "1.4.2"


如果您确定要包含jQuery,只需更改附加脚本标记的代码部分即可。

在脚本的底部。 更改

 // 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(); } })(); 

 // 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(); })(); 

Spokey给出的解决方案部分正确。

为了在本地提供Anywhere脚本,您还需要对代码进行一些修改,以允许域指向Intuit站点。 这样,蓝点菜单上的CSS和应用程序链接被正确地重定向到Intuit的域。

(注意:更新intuit.ipp.ourDomain变量将不会如上所述。)

这是我修改的内容:

20-40行包含:

 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]; 

我替换为这些:

 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"; 
Interesting Posts