简体   繁体   English

如何使用JavaScript更改iframe中的所有链接

[英]How to Change All Links inside iframe with javascript

I want to change all links of my site. 我想更改网站的所有链接。 Suppose a link given by .Example http://www.google.com/ changes to http://www.example.com/?redirect=http://www.google.com/ 假设.Example提供的链接http://www.google.com/更改为http://www.example.com/?redirect=http://www.google.com/

I use this function and it works but the links inside the iframe don't change 我使用了此功能,但可以正常使用,但iframe中的链接没有改变

 window.onload = function() {
      var anchors = document.getElementsByTagName("a");

for (var i = 0; i < anchors.length; i++) {
    anchors[i].href = "http://www.example.com/?redirect=" + anchors[i].href
}
}

I want to change the links inside iframe too. 我也想更改iframe中的链接。

如果iframe从其他域加载内容,则无法访问该内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM