javascript - 打开 iframe 内部的链接 iframe 外部的链接

标签 javascript html iframe

我使用的 iframe 代码类似于:

<iframe src="/comment_contents.php?profile_id=2850" height="100%" width="100%" style="border: none;">
</iframe>

在另一个页面的 Bootstrap 模式中 (/profile_comments.php?profile_id=2850)。

iframe 页面 (/comment_contents.php?profile_id=2850) 内的 HTML 内容如下所示:

<form method="post" action="/comment_contents.php?profile_id=2850" class="form-comment">
  <div class="form-comment-contents">
    <input type="text" name="comment" value="" class="comment-text">
    <input type="submit" value="Comment" class="comment-submit">
    <br><br>
    <a href="/view_profile.php?id=2851">
      <img src="img/profile2851.jpg" class="circle-comments" alt="Emma Watson">
    </a>
    <div class="comment-text lead">You are just awesome!</div>
    <br>
    <a href="/view_profile.php?id=2852">
      <img src="img/profile2852.jpg" class="circle-comments" alt="Bill Gates">
    </a>
    <div class="comment-text lead">You are Cool!</div>
  </div>
</form>.

您可能已经注意到有一个代码:

<a href="/view_profile.php?id=2852">...</a>

因此,当用户单击它时,会在 iframe 内打开一个“个人资料 View ”页面。但我希望链接不是在 iframe 中打开,而是在外部打开。我的意思是,在地址栏中。

是否有任何javaScript或其他东西可以在URL栏中打开链接URL(在iframe内)?

最佳答案

只需将 target="_top" 添加到该链接

<a href="/view_profile.php?id=2851" target="_top"><img src="img/profile2851.jpg" class="circle-comments" alt="Emma Watson"></a>

关于javascript - 打开 iframe 内部的链接 iframe 外部的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45810546/

相关文章:

html - 使用-webkit-overflow-scrolling 安全吗?

html - 尝试使用 margin-left 和 margin-right 将以前绝对定位的元素居中

javascript - 保护对 Web 服务的 JavaScript 请求

javascript - 如果将项目放入数组并排序,则确定项目的潜在索引。

php - 我可以使用 Manifest 或 Appcache 文件定位特定的浏览器/设备,或者只是从桌面浏览器中排除 appcache 吗?

html - 如何将 CSS 应用于 iframe?

javascript - 如何将 css 规则应用于 Javascript 表达式?

javascript - 检查 javascript 与 Internet Explorer 的兼容性

html 链接导航到另一个页面的部分

html - 如何避免零高度嵌套 flexbox 的 Chrome 错误?