首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Intuit Anywhere脚本重装jQuery

Intuit Anywhere脚本重装jQuery
EN

Stack Overflow用户
提问于 2013-07-22 23:20:39
回答 2查看 236关注 0票数 2

我们的应用程序加载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被重载?

谢谢,福雷斯

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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,只需更改代码中附加脚本标记的部分。

在脚本的底部。变化

代码语言:javascript
复制
// 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();
    }
})();

代码语言:javascript
复制
// 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
EN

Stack Overflow用户

发布于 2013-10-06 08:27:54

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

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

(注意:更新intuit.ipp.ourDomain变量不会像上面所说的那样工作。)

下面是我修改的内容:

第20-40行包含:

代码语言:javascript
复制
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];

我将其替换为:

代码语言:javascript
复制
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";
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17791357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档