使用iframe中的js将子iframe重定向到相对网址-但url相对于父网址 [英] Redirecting child iframe to relative url, using js within iframe - but url is relative to the parent

查看:225
本文介绍了使用iframe中的js将子iframe重定向到相对网址-但url相对于父网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些我没想到的有趣行为.我有一个包含iframe的页面,并且在该iframe中有一个javascript函数可重定向其自己的窗口.

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.

我从父框架调用iframe的js函数.我的预期行为是,它将相对于iframe的现有位置将iframe重定向到新页面.

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.

您可以在此处查看演示

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

我在这里做错什么了吗,还是只需要在绝对URL中为我的重定向编写代码?

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

发现这个听起来很相似的线程.但是没有人想出答案:

Found this thread that sounds very similar. However no one came up iwth an answer for it:

在子iframe中为window.location使用相对URL

推荐答案

更改:

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

收件人:

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

这样,moveMe在iframe的上下文中执行.

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

这篇关于使用iframe中的js将子iframe重定向到相对网址-但url相对于父网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆