Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更改动态创建的iframe的内容_Javascript_Jquery_Iframe - Fatal编程技术网

Javascript 更改动态创建的iframe的内容

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://" +

我们有一个无法触及源代码的应用程序。这就是为什么我不能将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://" + 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')