javascript动态地将javascript添加到iframe
下面的代码将动态添加一个iframe,有没有办法将javascript动态插入这个iframe Thxjavascript动态地将javascript添加到iframe,javascript,iframe,Javascript,Iframe,下面的代码将动态添加一个iframe,有没有办法将javascript动态插入这个iframe Thx 不,您不能将代码从另一个域插入到文档中。这是一种由浏览器强制实施的安全措施,用于防止跨站点脚本(XSS)和网络钓鱼攻击。否,您不能将代码从另一个域插入到文档中。这是一种由浏览器强制执行的安全措施,用于防止跨站点脚本(XSS)和网络钓鱼攻击。我认为它将是这样的: var script=iframe.createElement('script'); script=iframe.stand
不,您不能将代码从另一个域插入到文档中。这是一种由浏览器强制实施的安全措施,用于防止跨站点脚本(XSS)和网络钓鱼攻击。否,您不能将代码从另一个域插入到文档中。这是一种由浏览器强制执行的安全措施,用于防止跨站点脚本(XSS)和网络钓鱼攻击。我认为它将是这样的:
var script=iframe.createElement('script');
script=iframe.standardCreateElement('script');
script.setAttribute('src','http://localhost/jquery-1.3.2.js');
script.setAttribute('type','text/javascript');
iframe.lastChild.firstChild.appendChild(script);
注意,如果iframe和holder页面位于同一个域中,或者如果您从bookmarklet或浏览器扩展/插件调用它,则可以执行此操作。我认为它类似于:
var script=iframe.createElement('script');
script=iframe.standardCreateElement('script');
script.setAttribute('src','http://localhost/jquery-1.3.2.js');
script.setAttribute('type','text/javascript');
iframe.lastChild.firstChild.appendChild(script);
注意,如果iframe和holder页面位于同一个域中,或者如果您从bookmarklet或浏览器扩展/插件调用它,则可以执行此操作。这应该可以。。。
也许您正在尝试创建以下内容:
<body onload="initialize()">
<script language="JavaScript">
function initialize() {
var testFrame =
document.createElement("IFRAME");
testFrame.id = "testFrame";
testFrame.name = 'hehe';
testFrame.src = "http://www.seekload.tk";
testFrame.style.border='20px';
testFrame.style.width='900px';
testFrame.style.height='300px';
testFrame.style.frameBorder = 10;
testFrame.style.overflow = "hidden";
testFrame.style.align = "left";
testFrame.style.display = "block";
testFrame.style.fontSize = "10px";
document.body.appendChild(testFrame);
}
</script>
函数初始化(){
var测试框架=
document.createElement(“IFRAME”);
testFrame.id=“testFrame”;
testFrame.name='hehe';
testFrame.src=”http://www.seekload.tk";
testFrame.style.border='20px';
testFrame.style.width='900px';
testFrame.style.height='300px';
testFrame.style.frameBorder=10;
testFrame.style.overflow=“隐藏”;
testFrame.style.align=“left”;
testFrame.style.display=“block”;
testFrame.style.fontSize=“10px”;
document.body.appendChild(testFrame);
}
PS:您在编码中犯了一些错误,请尝试上面的方法。这应该可以。。。
也许您正在尝试创建以下内容:
<body onload="initialize()">
<script language="JavaScript">
function initialize() {
var testFrame =
document.createElement("IFRAME");
testFrame.id = "testFrame";
testFrame.name = 'hehe';
testFrame.src = "http://www.seekload.tk";
testFrame.style.border='20px';
testFrame.style.width='900px';
testFrame.style.height='300px';
testFrame.style.frameBorder = 10;
testFrame.style.overflow = "hidden";
testFrame.style.align = "left";
testFrame.style.display = "block";
testFrame.style.fontSize = "10px";
document.body.appendChild(testFrame);
}
</script>
函数初始化(){
var测试框架=
document.createElement(“IFRAME”);
testFrame.id=“testFrame”;
testFrame.name='hehe';
testFrame.src=”http://www.seekload.tk";
testFrame.style.border='20px';
testFrame.style.width='900px';
testFrame.style.height='300px';
testFrame.style.frameBorder=10;
testFrame.style.overflow=“隐藏”;
testFrame.style.align=“left”;
testFrame.style.display=“block”;
testFrame.style.fontSize=“10px”;
document.body.appendChild(testFrame);
}
PS:您在编码中犯了一些错误,请尝试上面的方法