我有一个插件,用于记录任何网站上的用户操作。 操作记录在同一浏览器的不同窗口中。 对于IE,它可以在除Iframe之外的所有站点上正常运行。 脚本在具有Iframe的网站上被阻止,并出现以下错误: SCRIPT5:访问被拒绝。
它是一个自创的插件。
错误在window.open上 它没有正确打开新窗口
以下是该插件的摘要。
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>');
使用警报(窗口)在所有网站上显示“[对象窗口]”..但在有iframe的网站上,它只显示“[object]”
请指导。
答案 0 :(得分:3)
我不知道你使用的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%;
}
答案 1 :(得分:0)
在运行插件之前消除iframe
function banish() {
$('iframe').remove();
}
答案 2 :(得分:0)
这对我有用......
var tableToExcel = (function () {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
return function (table, name, filename) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
document.getElementById("dlink").href = uri + base64(format(template, ctx));
document.getElementById("dlink").download = filename;
document.getElementById("dlink").click();
}
})()
谢谢大家的帮助。