我使用的 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/