【问题标题】:JQuery plugin issue with IFrameIFrame 的 JQuery 插件问题
【发布时间】:2015-07-27 00:47:13
【问题描述】:

我有一个插件可以记录用户在任何网站上的操作。 这些动作记录在同一浏览器的不同窗口中。 对于 IE,它可以在除具有 iframe 的网站之外的所有网站上正常工作。 该脚本在具有以下错误的 iframe 的站点上被阻止: SCRIPT5:访问被拒绝。

它是一个自创的插件。

错误出现在 window.open 上 它没有正确打开一个新窗口

下面是插件的sn-p。

newwindow = window.open("", "ScriptGen", "menubar=0,directories=0,toolbar=no,location=no,resizable=yes,scrollbars=yes,width=450,height=250,titlebar=0"); 

newwindow.document.write('<title>New Console</title>');

使用 alert(window) 在所有网站上显示“[object Window]..但在有 iframe 的网站上,它只显示“[object]”

请指导。

【问题讨论】:

  • 首先,插件的名称是什么?
  • 它是一个自创插件。
  • IE?它是在它的每个版本上还是在某些特定版本上?
  • 是的...它被称为同源策略。基本上,如果页面不在同一个域/url 路径上,您将无法触摸它或对其进行任何操作。您可以使用它做某事的唯一方法是使用幕后代理。 ternarylabs.com/2011/03/27/… 或使用staticapps.org/articles/cross-domain-requests-with-cors 之类的解决方案
  • 我都试过了,但都不行,我无法从新窗口访问网络,更改原始窗口的域都不起作用。还有其他解决方案吗?

标签: javascript jquery internet-explorer iframe


【解决方案1】:

我不知道你用的是什么版本的jQuery,但我认为你应该更新到1.11.0:

https://jsfiddle.net/j3LaC/ - 用 1.10.1(不工作)和 1.11.0(工作)试试这个

HTML:

<div id="body"></div>
<input id="button" type="button" value="Submit iframe"/>

JavaScript:

var iframe = $("<iframe></iframe>").appendTo("#body")[0];
var doc = iframe.document;
var content = '<form method="get"><input name="hidden" type="hidden" value="123"/></form>';
doc = iframe.contentDocument;
doc.writeln(content);
doc.close();

$('input#button').click(function () {
    $('iframe').contents().find('form')[0].submit();
});

CSS:

iframe {
    height: 300px;
    width : 100%;
}

【讨论】:

  • 感谢您的回复...我试过了,但即使这样似乎也不能解决我的问题...
【解决方案2】:

在运行插件之前消除 iframe

function banish() {
    $('iframe').remove();
}

【讨论】:

    【解决方案3】:

    这对我有用...

    try{
               newwindow = window.open("", "ScriptGen", "menubar=0,directories=0,toolbar=no,location=no,resizable=yes,scrollbars=yes,width=450,height=250,titlebar=0");
                console.log(newwindow.document);
            }
            catch (error) {
                console.log("Error catched");
                newwindow.close();
                useDomain = true;
                var domain = document.domain;
                newwindow = window.open("javascript:document.write('<script>document.domain=\"" + document.domain + "\"</script>')", "ScriptGen", "menubar=0,directories=0,toolbar=no,location=no,resizable=yes,scrollbars=yes,width=450,height=250,titlebar=0");
        }
    

    感谢大家的帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多