父级中的锚点链接到iframe内容中的节

时间:2017-05-30 01:54:31

标签: javascript html iframe hyperlink

说我有以下内容:

<!-- index.html -->
<a href="#heading32">Link to Section</a>

<section id="heading1">Section Name</section>
<div>Content</div>
<section id="heading2">Section Name</section>
<div>Content</div>
<section id="heading3">Section Name</section>
<div>Content</div>
<!-- More sections -->
<section id="heading32">Section Name</section>
<div>Content</div>
<!-- More sections -->

基本上,我希望实现类似于您在维基百科等网站中找到的功能,您可以在其中单击目录中的链接,然后将页面向下滚动到链接部分。

现在,我需要更改代码如下:

<!-- index.html -->
<a href="#heading32">Link to Section in iFrame</a>
<iframe src="content.html">

<!-- content.html -->
<section id="heading1">Section Name</section>
<div>Content</div>
<section id="heading2">Section Name</section>
<div>Content</div>
<section id="heading3">Section Name</section>
<div>Content</div>
<!-- More sections -->
<section id="heading32">Section Name</section>
<div>Content</div>
<!-- More sections -->

基本上,目录将在父容器中,单击一个应该将iframe内容转到链接部分 - 与之前相同的功能,只是内容现在已重新定位。

我应该如何进一步修改我的实现来实现它?内容从Microsoft Word文档导出,因此内容HTML文档本身无法修改。但是,我的系统框架允许我添加脚本和样式表,但这就是它。

1 个答案:

答案 0 :(得分:0)

认为已经在另一个stackoverflow问题中询问并回答了此变体。 open link in iframe

http://jsfiddle.net/HnXFj/2/

基本上这个:

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.15</version>
</dependency>