我们的应用程序加载jQuery 1.10.2,然后从Intuit加载https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js。anywhere脚本正在将<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>添加到头部并重新加载jQuery。
这将擦除名称空间并破坏我们的大部分代码。脚本不应该看到jQuery已经加载了吗?我们如何防止jquery被重载?
谢谢,福雷斯
发布于 2013-07-22 23:28:36
编辑:
问题似乎是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"
如果您确定要包含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();
})();发布于 2013-10-06 08:27:54
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";https://stackoverflow.com/questions/17791357
复制相似问题