如何防止iframe打开新链接?

时间:2015-07-24 04:35:33

标签: javascript html iframe

背景故事

我有一些带宽问题,所以我现在想把我好的网站带到新的更多带宽网站而不会让客户丢失了我的新网站的金砖,因为客户真的是老人,所以这是最好的方式

我使用的代码

<!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>

问题

每当我按下左侧的一个链接时,我就会被发送到目标站点。但是,当我按导航中的链接时,页面仍然在iframe中。

使用iframe在oldwebsite.com上打开newwebsite.com 用户在newwebsite.com中点击的链接,用户不得重定向到newwebsite.com,用户必须在浏览器中看到oldwebsite.com。

我可能不会很好地解释这一点,但我可以an animated illustration

大问题

如何防止我的新网站表现出w3school的侧边栏行为方式。

3 个答案:

答案 0 :(得分:1)

我能看到的唯一区别是:

导航栏中的锚点是:

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

侧面导航栏中的锚点是:

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

target="_top"部分出现问题,因为_top会在窗口的整个正文中打开链接的文档。

删除目标,它将起作用。

答案 1 :(得分:0)

您无法控制外部网站。 你可以尝试使用目标propritie,但它可能不会工作!

答案 2 :(得分:0)

为了防止网站表现出w3school的侧边栏行为,我必须执行以下操作:

  1. 避免放置目标。 某些目标会以影响iframe的方式打开链接文档。

  2. 更改目标。如果需要定位,那么目标应该是_self,_parent和_top无法正常工作。