views:

106

answers:

1

In my (school) website we use Iframes to display class blogs (on blogger). This works well EXCEPT if the user then clicks on (say) a photo inside the iframe. Blogger (in this case) then displays the photo in the whole browser window and the back button loops; that is if the back button is hit, the browser (IE, FF, Chrome) stays on the same page. The only way out is for the user to jump back two pages (which many of our users don't know how to do). I've read a lot of posts on back buttons and iframes and there doesn't appear to be a simple solution. Bear in mind that I don't have control over the iframe content (so no embedded back buttons in the frame are possible). Ideas anyone?

A: 

The solution I would use would be to loop through the iframe content after it has been loaded and set target attributes on links in the iframe so that they open in either the iframe, or in a new window. Here's an example using jQuery:

$('#iframeID').contents().find('a').attr('target', '_blank');

You could do something similar using a loop and DOM methods, I'll post some code to do that if your not sure how to go about it.

EDIT: can't access the content if its cross domain, so this wouldn't work in this case

Ryan Lynch
You can't access the iframe's content when it's not on the same domain (which it isn't, in this case).
mercator
I'm realizing that now as I try to test this on JSBin. Here is a link to the test page if anyone wants to test out an answer. http://jsbin.com/onoge
Ryan Lynch