Javascript 更改动态创建的iframe的内容
我们有一个无法触及源代码的应用程序。这就是为什么我不能将javascript代码注入iframe。我尝试通过jQuery和JavaScript操作图像按钮src,如下所示:Javascript 更改动态创建的iframe的内容,javascript,jquery,iframe,Javascript,Jquery,Iframe,我们有一个无法触及源代码的应用程序。这就是为什么我不能将javascript代码注入iframe。我尝试通过jQuery和JavaScript操作图像按钮src,如下所示: // there isn't id of the iframe so I used to catch by tag $("input:image", window.parent.frames[0].document).each(function() { $(this).attr("src", "http://" +
// there isn't id of the iframe so I used to catch by tag
$("input:image", window.parent.frames[0].document).each(function() {
$(this).attr("src", "http://" + document.location.hostname + "/theme/img/buttonDownArrow.png")
});
// other attempt
document.getElementsByTagName('iframe').onload = function() {
$("input:image", window.parent.frames[0].document).each(function() {
$(this).attr("src", "http://" + document.location.hostname + "/theme/img/buttonDownArrow.png")
});
}
但什么也没发生。当我在iframe加载后在控制台中尝试上述代码时,代码正常工作。我把源代码放在页面的末尾,但什么也没发生。是否仍然可以操纵加载的iframe内容?这可能取决于位于不同的域。如果iframe与加载在iframe中的页面位于不同的域中,则当您试图“从上方”操作代码时,可能会遇到安全问题,就像您试图“从下方”影响框架一样。我用以下方法解决了此问题 这里是棘手的部分:
$('#form1').contents().find('input:image')
它在同一个域上。
$('#form1').contents().find('input:image')