[英]How to open a link inside of iframe when a user trys to open link in a new tab?
在最终决定将其发布到这里之前,我尝试了一段时间以使其正常工作。
因此,我有一个导航栏,导航栏中的每个项目都会打开我在主页上拥有的iframe中的链接。
主页(index.php)具有所有这些代码
我的导航栏:
<ul id="nav">
<li style="width: 20%">
<a href="home.php" target="iframe" id="navBarLeft">Home</a>
</li>
<li style="width: 30%">
<a href="saleItems.php" target="iframe" >Sale Items</a>
<ul>
<li><a href="saleFlyer.php" target="iframe" id="navMid">Sale Flyer/Coupons</a></li>
</ul>
</li>
<li style="width: 30%">
<a href="location.php" target="iframe">Store Information</a>
</li>
<li style="width: 20%">
<a href="contact.php" id="navBarRight" target="iframe">Contact Us</a>
</li>
</ul>
我的iframe:
<iframe src="home.php" name="iframe" id = "iframeID" scrolling="no"></iframe>
因此,默认情况下它将加载home.php,并且用户可以浏览导航栏中的所有链接,并且该链接中的相应php文件将加载到iframe中。
但是,如果用户尝试在新标签页中打开它,则该页面会显得很奇怪,因为它们都针对iframe进行了优化。
以任何方式,如果用户确实尝试从新标签中的导航栏打开链接,则会加载index.php(我的首页),并且在iframe中,他们尝试使用新标签打开的页面会显示在改为使用iframe
您可以挂在onclick链接上,该链接内是更改iframe src的代码。
<a href="saleItems.php" onclick="document.getElementById('iframeID').src = this.getAttribute('href'); return false;" >Sale Items</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.