Html 在同一页面打开链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5777061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening a link in the same page
提问by ayman
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?
我在 HTML 文档中放置了一个链接。如何在同一页面内的link1.html
链接下打开链接文档 ( ) ?
links.html
:
links.html
:
<body>
<h3>Links</h3>
<a href="link1.html">link1</a>
</body>
output like:
输出如:
Links [link1]
链接 [link1]
content of link1.html
link1.html 的内容
回答by ayman
<a href='link1.html' target='myIframe'>link1</a><br />
<iframe name='myIframe'></iframe>
If you want it to be less crappy, I suggest you use JavaScript.
如果你想让它不那么糟糕,我建议你使用 JavaScript。
回答by Alba Mendez
As has been sayed in the comments:
Probably what you want is an <iframe>
. It can be used to embeda web page into an HTML document. You can see more info here. Below is an example.
正如评论中所说:
可能你想要的是一个<iframe>
. 它可用于将网页嵌入到 HTML 文档中。您可以在此处查看更多信息。下面是一个例子。
In your case:
在你的情况下:
<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>
Update:To show the IFrame when the link's clicked, you can use this code instead:
更新:要在单击链接时显示 IFrame,您可以改用以下代码:
<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>
回答by Loga
Try to use the property tag "Target" which is used to specify, where the document to be opened, means new window or same page or new tab.. eg: Click Here
尝试使用属性标签“目标”,它用于指定要打开的文档的位置,意味着新窗口或同一页面或新选项卡.. 例如:单击此处
There are six values of the target tag like parent,blank and so on..
目标标签有六个值,如 parent、blank 等。
回答by Cedric Gatay
I am afraid you'll have to do this using some kind of javascript Ajax call to load the other page under the link. Another technique could be to include in your link1.html the same header as in links.html, but you're going into copy/paste spaghettiness...
恐怕您必须使用某种 javascript Ajax 调用来加载链接下的其他页面。另一种技术可能是在您的link1.html 中包含与links.html 相同的标题,但您将进入复制/粘贴意大利面...