好的,首先感谢您的关注。我在 3 个不同的 html 文档中有 3 个 iframe。组织方式如下:
在 iframemain.html 中我有:
<iframe src="iframeparent.html" width="100%" height="600">
</iframe>
在 iframeparent.html 中我有:
<iframe src="iframeson.html" width="90%" height="350" name="_parent">
</iframe>
在 iframeson.html 中我有:
<iframe src="http://anywebsite.com/samplepage.html" width="80%" height="300">
</iframe>
我这样做是因为 http://anywebsite.com/samplepage.html 链接加载到主窗口(iframemain.html),而不是我想要的,我希望我可以捕获目标并加载内容 iframeparent.html 而不影响 iframemain.html
我澄清,我无法控制以下内容:http://anywebsite.com/samplepage.html ,但是您的链接加载到主窗口中很烦人,所以我希望所有这些链接都加载到同一个 iframe 中或 iframeparent.html 中的大部分内容
这可以用 Javascript 或 Jquery 实现吗?感谢您的回答。
最佳答案
看看我是否理解正确
您想要为页面添加框架http://anywebsite.com/samplepage.html在 iframemain 上。
该页面有一堆带有 target="_parent"或更糟糕的 "_top"的链接
您希望所构建的页面不定位 iframemain,而是让所有链接保留在该框架中。
如果链接目标为 _parent,那么您的解决方案是正确的。如果他们的目标是 _top,您将需要在服务器上使用代理。如果他们改变定位链接的方式(例如使用 javascript 或基本目标),它就会中断,但想法是你有
<iframe src="yourproxy.php?url=http://anywebsite.com/samplepage.html" width="80%" height="300"></iframe>
然后,将所有 _top
和/或 _parent
替换为 _self
但请显示一些链接示例(您可以更改 URL 以保护您的客户),以便我们更好地提供帮助
关于javascript - 捕获 iframe 上的目标链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17626964/