更改动态创建的iframe的内容(Changing content of dynamically created iframe)

编程入门 行业动态 更新时间:2024-10-28 03:20:27
更改动态创建的iframe的内容(Changing content of dynamically created 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://" + 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内容?

We have an application that we can't touch source code. That is why I can't inject javascript code into iframe. I tried to manipulate an image button src by jQuery and JavaScript as follow :

// 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") }); }

but nothing happen. When I tried above code in console after iframe loaded works properly. I put source code end of the page but nothing happened too. Is there anyway to manipulate loaded iframe content?

最满意答案

这可能取决于在不同的域上。 如果iframe与iframe中加载的页面位于不同的域中,则在尝试“从上方”操作代码时可能会遇到安全问题,就像您尝试“从下方”影响框架一样。

I solved this problem with the following way.Thanks Martin for the snippet

$('[data-dojo-attach-point="iframeViewer"]').ready(function() { $('#form1').contents().find('input:image').each(function() { $(this).attr('src', 'http://' + document.location.hostname + '/theme/img/buttonDownArrow.png'); $(this).addClass('modifyComboArrowButton'); $(this).hover( function() { $(this).attr('src', 'http://' + document.location.hostname + '/theme/img/buttonDownArrow_hover.png') }, function() { $(this).attr('src', 'http://' + document.location.hostname + '/theme/img/buttonDownArrow.png') }) }); $('.ComboBoxDelButton').each(function() { $(this).addClass('modifyComboDeleteButton'); $(this).hover().addClass('modifyComboDeleteButton:hover'); }); })

Here is the tricky part :

$('#form1').contents().find('input:image')

更多推荐

本文发布于:2023-08-06 23:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内容   动态   iframe   Changing   dynamically

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!