mulllhausen
mulllhausen

Reputation: 4435

javascript let iframe become parent

i have one iframe on my page which has a different domain to that of my site. i know i can't access anything inside the iframe from the parent window, but can i make that iframe take over my entire page - ie redirect the parent to the url of the iframe?

so far i have tried things like

window.location.href = iframe.contentWindow.location.href;

but the browser won't allow that - i guess it isn't smart enough to realise that the = assignment is for the purposes of redirecting and not storage for later inspection.

is there another way of doing this on all modern browsers?

Upvotes: 0

Views: 385

Answers (2)

ngi
ngi

Reputation: 388

Why don't you try with the iframe src attributes?

with jquery:

window.location.href = $('#iframeid').attr('src');

or:

window.location.href = document.getElementById('#iframeid').src;

Upvotes: 1

David Hellsing
David Hellsing

Reputation: 108500

How about:

window.location = iframe.src;

Upvotes: 2

Related Questions