Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript window.location iframe, make parent window go to location

Tags:

I know on the same page frame or parent I can make either go to something via window.location however is there a means of checking to see if I am in the iframe and if so make the top (parent window) location go somewhere?

like image 327
chris Avatar asked Jun 07 '12 23:06

chris


People also ask

How do you force a link from iframe to be open in the parent window?

1 Expert Answer To force a single link from iframe to open in the parent window: add target="_PARENT" within that links anchor tag. To force ALL links from iframe to open in the parent window: add the base tag with target="_PARENT" in the head section of the iframe html page.

Can an iframe get parent URL?

You can still access parent from within an iframe even though you can't access anything useful on it. This code will never cause an error even when crossing origins.


1 Answers

This is a simple code to check if your page is loaded in iframe:

if (window.location != window.parent.location)
    window.parent.location = "http://someurl";
like image 61
WojtekT Avatar answered Sep 21 '22 19:09

WojtekT