开发者

Redirecting child iframe to relative url, using js within iframe - but url is relative to the parent

Some interesting behavior that I didn't expect. I have a page which contains an iframe, and in that iframe there's a javascript function that redirects its own window.

I call the iframe's js function from the parent frame. My expected behavior is that it will redirect the iframe to a new page, relative to the iframe's existing location.

Instead, it gets redirected relative to the parent frame's location.

You can see a demo here:

http://thedailynathan.com/files/outlink/parent/parent.html

Am I doing something wrong here, or will I just have to code in an absolute url for my redirect?

Found thi开发者_StackOverflows thread that sounds very similar. However no one came up iwth an answer for it:

Using relative url for window.location in child iframe


Change the:

document.getElementById("myframe").contentWindow.moveMe()

to:

document.getElementById("myframe").contentWindow.location = "javascript:moveMe()"

This way, the moveMe executed in the iframe's context.


Try this one, it works for me.

<script>function RedirectPage(){ document.getElementById("frame1").src = "http://WWW.microsoft.com";}</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜