在同一页面中打开链接 [英] Opening a link in the same page

查看:67
本文介绍了在同一页面中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在HTML文档中放置了一个链接.如何在同一页面的链接下打开链接的文档( link1.html )?

I have put a link in an HTML document. How can I open the linked document (link1.html) under the link within the same page?

links.html :

links.html:

<body>
    <h3>Links</h3>
    <a href="link1.html">link1</a> 
</body>

输出如下:

链接[link1]

推荐答案

正如评论中所说:
您可能想要的是< iframe> .它可以用于将网页嵌入到HTML文档中.您可以在此处查看更多信息.下面是一个示例.

As has been sayed in the comments:
Probably what you want is an <iframe>. It can be used to embed a web page into an HTML document. You can see more info here. Below is an example.

您的情况:

<body>
    <h1>Links</h1>
    <a href="link1.html">link1</a>

    <h2>Contents of link1</h2>
    <iframe src="link1.html" width="500" height="400"></iframe>
</body>

更新:要在单击链接时显示IFrame,可以改用以下代码:

Update: To show the IFrame when the link's clicked, you can use this code instead:

<body>
    <h1>Links</h1>
    <a href="#" onclick="document.getElementById('contents1').style.cssText = ''">link1</a>

    <div id="contents1" style="display:none;">
        <h2>Contents of link1</h2>
        <iframe src="link1.html" width="500" height="400"></iframe>
    </div>
</body>

这篇关于在同一页面中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆