js控制iframe弹出窗口
有这样一种情况:
我在iframe里面嵌了一个网页(这个网页可能是来自网络)
如果网页里面含有像
<script>
function changelocation(){
parent.location.href="b.htm";
}
</script>
</head>
<body>
<a href="#" onclick="changelocation();">跳转</a>
</body>
这样的代码,那页面跳转之后就会覆盖掉了原来的iframe页,我想让这个跳转之后的
页面在iframe里面显示。但是只能是自己另外建一个js文件往这个网页上注入,
因为这个网页不一定是我写的,可能会是一个网络资源。
求解决办法。下面是需求的例子:
a.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script>
function changelocation(){
parent.location.href="b.htm";
}
</script>
</head>
<body>
<a href="#" onclick="changelocation();">跳转</a>
</body>
</html>
b.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
bbbbbbbbbbbbbb
</body>
</html>
frame.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<center>
<iframe src="a.htm"/>
</center>
</body>
</html>