简体   繁体   中英

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/

I use this function and it works but the links inside the iframe don't change

 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从其他域加载内容,则无法访问该内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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