需要帮助解决一个简单的问题!它具有以下标准:
1) 单击 iframe 更改父页面中的图像链接,单击另一个 iframe 图像链接将父更改为另一个页面(见下文)。
听起来可能很简单,但我已经用谷歌搜索了好几天,并查看了许多论坛。代码可以是 html css 或 js,但请尽可能简单地回答任何问题,并发布一个完整的工作示例,因为我是编码新手或重新编码测试站点: http: //www.howiepotter.com/parent。 html
需要帮助解决一个简单的问题!它具有以下标准:
1) 单击 iframe 更改父页面中的图像链接,单击另一个 iframe 图像链接将父更改为另一个页面(见下文)。
听起来可能很简单,但我已经用谷歌搜索了好几天,并查看了许多论坛。代码可以是 html css 或 js,但请尽可能简单地回答任何问题,并发布一个完整的工作示例,因为我是编码新手或重新编码测试站点: http: //www.howiepotter.com/parent。 html
http://reference.sitepoint.com/html/a/target
“_最佳”
加载顶级框架集中的内容(实际上是整个浏览器窗口),无论当前框架位于多少嵌套级别
<a href="page" target="_top">Replace parent url!</a>
Change your link from this:
<a href="link-here.html">
To this:
<a href="#" onclick="top.window.location.href='yourURL';">
If you want, you could just put the onclick
handler on the image instead and get rid of the anchor.
Note that this is not the correct place to have javascript (handlers should be bound from a .js file, not in markup), but i get the feeling you are looking for a surgical answer and don't care much for best practices.
edit: as Victor Nicollet pointed out, this will throw a security exception if your iframe and parent page do not share domains. see http://en.wikipedia.org/wiki/Same_origin_policy
就我而言,我使用了以下内容
if (window.self !== window.top) { // checking if it is an iframe
window.parent.location.href = websiteUrl;
} else {
window.location.href = websiteUrl;
}
如果@biziclop 决定删除他的答案,因为他似乎威胁要在评论中这样做,这又是他的答案,非常有用:
http://reference.sitepoint.com/html/a/target
“_最佳”
加载顶级框架集中的内容(实际上是整个浏览器窗口),无论当前框架位于多少嵌套级别
<a href="page" target="_top">Replace parent url!</a>