html - 如何使用 CSS 更改 iframe 页面而不更改父页面和外部链接

标签 html css iframe

我正在处理一个网页,我需要在该网页上单击用于更改父页面中的 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>

最佳答案

为了使您的链接指向 iframe,您必须向该框架添加“name”属性,与“id”无关

<iframe id="MSL" name="MSL" src="http://www.yahoo.com" width="975" height="800">
</iframe>

此外,您的 DOM 结构非常糟糕,您不应该在段落中嵌套 iFrame。简而言之, anchor 元素中的target属性需要匹配iFrame中的name属性,除非它是保留的,如“_blank”、“_self”、“_parent”或“_top”。

关于html - 如何使用 CSS 更改 iframe 页面而不更改父页面和外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21652600/

相关文章:

html - 更改默认的 gumby 样式按钮

javascript - 如何用我当前的代码切换标志?

jquery - 为文本区域的每一行设置动画

html - 如何嵌入 youtube 直播聊天

css - 如何设置 iframe 滚动条的样式?

css - Chrome 上链接的奇怪悬停行为

javascript - 突出显示空输入字段

css - 什么是 CSS 中的规则以及 "at"用于什么

javascript - impress.js 中的 Bootstrap 幻灯片

javascript - 从外部域调整 iframe 高度