简体   繁体   English

如何防止iframe打开新链接?

[英]How to prevent iframe from opening new links?

Backstory 背景故事

I have some bandwidth problem so I currently want to iframe me good ol'site to new more bandwidth site without customer lost the golden bricks to my new site since the customers are really really old people so this is the best way. 我遇到了一些带宽问题,因此我现在希望将自己的站点更好地扩展到新的带宽更高的站点,而客户却没有真正的老客户,因此客户不会在我的新站点上失去金砖块,所以这是最好的方法。

Code I use 我使用的代码

<!DOCTYPE html>
<html style="background-color:yellow; height:100%">
<head>

    <meta charset="utf-8">
    <title>Web in a Web</title>
</head>
<body style="background-color:orange; height:100%; width:100%"; min-height:100%; margin:0; padding:0>
 <iframe src="http://www.w3schools.com" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;">
    Your browser doesn't support iframes
</iframe>
</body>
</html>

Problem 问题

Whenever I press one of the link in the left side, I was sent to the target site. 每当我按下左侧的链接之一时,我就会被发送到目标站点。 However, when I press the link in the navigation, the page is still in the iframe. 但是,当我按导航中的链接时,页面仍在iframe中。

newwebsite.com is opened in oldwebsite.com using iframe whatever links users clicked in newwebsite.com, users must not redirected to newwebsite.com, users has to see oldwebsite.com in their browser. 无论用户在newwebsite.com中单击了什么链接,都可以使用iframe在oldwebsite.com中打开newwebsite.com,用户不得重定向到newwebsite.com,用户必须在浏览器中查看oldwebsite.com。

I might not explain this well but I can make an animated illustration 我可能无法很好地解释这一点,但我可以制作动画插图

The Big Question 大问题

How to prevent my new website from behaving the way w3school's sidebar behaves. 如何防止我的新网站出现w3school侧边栏的行为方式。

The only difference I could see is: 我能看到的唯一区别是:

Anchor points in the navigation bar are: 导航栏中的锚点为:

<a href="/default.asp" class="topnav_home" title="Home">&nbsp;</a>

Anchor points in the side navigation bar are: 侧面导航栏中的锚点为:

<a target="_top" href="default.asp" class="menu_default">JS HOME</a>

This target="_top" part is making a problem because _top opens the linked document in the full body of the window. 这个target="_top"部分出了问题,因为_top在窗口的整个正文中打开了链接的文档。

Remove the target and it will work. 删除目标,它将起作用。

You cannot control external websites. 您无法控制外部网站。 You can try to use target propritie but it prababily wont work! 您可以尝试使用目标属性,但无法正常工作!

To prevent the website from behaving the way w3school's sidebar behaves I must do the following: 为了防止网站出现w3school侧边栏的行为,我必须执行以下操作:

  1. Avoid Putting Target. 避免放置目标。 Some targets opens the linked document in a way that affects iframe. 某些目标会以影响iframe的方式打开链接的文档。

  2. Change The Target. 更改目标。 If target is necessary, then, the target should be _self, _parent, and _top not working properly. 如果需要目标,则目标应该是_self,_parent和_top无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM