2

I need to implement parent page redirection from iframe. I know that it is impossible to do in different domains due to browsers security. However I found that links have target attribute and tried to use it in the following way:

<a href="http://google.com" target="_top" id="testParentRedirect">someLink</a>

It works fine if I click this link manually, but I couldn't find cross-browser solution to simulate it using JavaScript.

document.getElementById('testParentRedirect').click();

This works fine in IE, however Firefox and Safari don't know click function :).

I tried to work with jQuery, but for some reason they don't simulate click event for links. (see following post)

I couldn't find any appropriate solution on Stack Overflow. Maybe someone could help me in it. I will appreciate it. :)

2

2 Answers 2

7

You can do this in javascript to exit a frame:

window.top.location = "http://google.com";
Sign up to request clarification or add additional context in comments.

Comments

3

You can try

top.location.replace( "http://google.com" );

in javascript to "escape" from the frame.

Edit: Using replace is slightly nicer, changed my answer to use that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.