我正在一个网页上工作,我需要能够点击在父页面中更改iframe的按钮。我认为这将是一项简单的任务,但无论我做什么,按钮都会打开一个新窗口而不是打开iframe中的页面。页面看起来很完美,iframe加载但当我单击父窗口中的按钮更改它在新选项卡中打开的页面时。以下是我使用的完整代码(减去更改的网页名称),如果有人可以指出我做错了请。
<head>
<style>
body
{
background-image:url(bg4.jpg);
background-repeat:no-repeat;
background-attachment:fixed;
background-position:top;
background-size:100%;
}
p.pos_fixed
{
position:fixed;
top:98px;
right:298px;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Stupid webpage that dont work</title>
</head>
<body>
<p class="pos_fixed">
<iframe id="MSL" src="http://www.yahoo.com" width="975" height="800">
</iframe>
<center>
<a href="http://www.google.com" target="MSL">
<img src="MSL.jpg" alt="MSL" width="42" height="42"></a>
</center>
</p>
</body>
</html>
答案 0 :(得分:0)
为了使您的链接定位到iframe,您必须将“name”属性添加到此类框架中,与“id”无关
<iframe id="MSL" name="MSL" src="http://www.yahoo.com" width="975" height="800">
</iframe>
此外,您的DOM结构非常糟糕,您不应该在段落中嵌套iFrame。简而言之,锚元素中的target属性需要匹配iFrame中的name属性,除非它是一个保留的属性,如“_blank”,“_ self”,“_ parent”或“_top”。