-5

I was wandering that if I could change the href attributes of all the links that are displayed within an IFrame. I had seen this system on many of the proxy site.

Please if anyone can provide me the code, I would be very grateful.

Liam
  • 27,717
  • 28
  • 128
  • 190

1 Answers1

2

Well actually you can, here is an example:

http://jsfiddle.net/2XXxW/4/ as example how it works

var ifrmame = document.getElementById('iframe');
var a = ifrmame.contentWindow.document.getElementsByTagName('a');
for (var i=0;i< a.length;i++) { 
    a[i].href = 'URL';
}

but iframes have to be the same origin, otherwise you cant access it for security reasons

Sergei Zahharenko
  • 1,514
  • 12
  • 16
  • well... fiddle just give and example how to work with content of iframe, no more no less. And it's nice to have it, as soon as you can quickly try it yourself, play with it, understand how it work... sadly fiddle 404 have no links... and it have to be same origin ... that's why – Sergei Zahharenko Dec 30 '13 at 13:43
  • sory. my bad :) thre are links, just noticed it have element with ID="body"... and chrome links it as id :) updated example – Sergei Zahharenko Dec 30 '13 at 15:45