I have iframe in the site which acts as an internal browser. I know that frames are generally bad idea but I was not able to find alternative. The question is how to prevent navigation of browser when user clicks a link inside iframe - only iframe has to be redirected, not ALL browser. Sites inside iframe are limited, very simple - mostly static HTML, maybe I can use javascript to add target='iframe_name' to each link inside iframe's HTML if it's possible.. ?
+1
A:
The normal operation of HTML <a>
tags is alread to replace only the current frame.
Here is a simple, sample page: http://gutfullofbeer.net/frames/able.html
when you click on the links in the box, the frame reloads. Those are just simple <a>
tags.
Pointy
2010-03-01 16:29:13
Yes, I noticed that thanks, but it seems that target is given explicitly so I may need to overwrite it somehow, however as I written in the comment above it's forbidden since iframe points to other domain.
pk4r
2010-03-04 19:30:17
A:
Yes, you can change all the links with this simple code:
iFrameText = iFrameText.replace(/(<a\s)/ig, "$1target='iframe_name' ")
This, can however create problems if you are having "target" set for some of the links. I think the latter will take the preference.
Sergiy Byelozyorov
2010-03-01 16:29:47
Thanks, though I made a mistake with assumption that I can access inner text of the iframe - it's forbidden since contents are fetched from other domain. I get permission denied error in Javascript. Are there any other workarounds to consider ?
pk4r
2010-03-04 19:28:57
You can put the code inside of the loaded pages (if that is possible) and check if you are running within the frame - then you can change the `target` attribute.As for JavaScript access denied, I believe it was done to prevent hidden parent document with single `<iframe>` taking the whole screen. This way you would be able to spy pages visited by user.
Sergiy Byelozyorov
2010-03-05 00:43:57