我有两页。我在第一个页面中加载了第二个页面。
在第二页,我有一个链接。
问题是,当我点击第二个页面中的链接时,它会在新的选项卡中打开。
如何在同一页中打开此链接,如iframe
下面是我的代码片段:
$( document ).ready(function() {
$('#second').load('second.html');
});
#second{width:100%; height:300px; border:1px solid blue;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<html>
<head>
<title>First page</title>
</head>
<body>
<div id="second"></div>
<!--
THis is my second page code ////////
<html>
<head>second page</head>
<body>
<a href="google.com">click here !</a>
</body>
</html>
-->
</body>
</html>
发布于 2017-02-11 09:12:40
将您的iframe命名为<iframe name="namedIf"></iframe>
然后在锚标记中使用目标属性<a href="link" target="namedIf"/>
但正如评论所说,谷歌不允许你在你的网站上iframe他们的内容。
更新
由于您没有使用iframe,因此我能想到的唯一方法就是“拦截”对已加载文档上的锚定标记的任何点击,并再次使用相同的函数来加载它。
$(function() {
$('#second').load('second.html', function(){
$("#second a").click(function (e) {
e.preventDefault();
$("#second").load($(this).attr("href"));
});
});
});
因此,当您的代码完成将second.html
加载到文档中时,代码将被执行。
https://stackoverflow.com/questions/42174071
复制相似问题