简体   繁体   English

根据链接显示iframe内容

[英]Display iframe content according to link

I have an iframe in my page and I want to display the content according to the link (anchor tag) selected. 我的页面中有一个iframe ,我想根据所选的链接(锚标签)显示内容。 I would like to achieve this using javascript. 我想使用javascript实现。

My doubts are: 我的怀疑是:

  1. How to retrieve which anchor tag is selected. 如何检索选择的锚标签。
  2. If I call javascript from onclick() function in anchor tag and don't add a href attribute, then the anchor tag (link) loses it hyperlink property. 如果我从锚标记中的onclick()函数调用javascript且未添加href属性,则锚标记(链接)将失去其超链接属性。 So how can I add a href attribute in this case 那么在这种情况下如何添加href属性

Give your iframe a name attribute, IE: 给您的iframe一个name属性,即IE:

<iframe src="startpage.html" name="content"></iframe>

Then when you create your links, set the target attribute to the same value. 然后,在创建链接时,将target属性设置为相同的值。 IE: IE浏览器:

<a href="nextpage.html" target="content">Next Page</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM