在HTML中打开另一个页面 [英] Opening another page in HTML

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

问题描述

在我的网站中,我在文件夹内有一个html文件,它位于索引文件旁边。我想将链接添加回索引文件。



例如,索引的URL将为example.com。第二页是example.com/pages/example.html。如何将用户发回索引页?

解决方案

假设您具有以下结构:

  website.com/index.html 
website.com/pages/example.html

您有三个选项 - 两个相对链接和一个绝对链接:



相对于 example.html

 < a href =../ index .html>返回索引< / a> 

相对于root(注意斜线):

 < a href =/ index.html>返回索引< / a> 

绝对值:

 < a href =http://example.com/index.html>返回索引< / a> 

我建议使用相对根目录,因为您的网站网址可能会在将来发生变化,所以您对于使用两种相对方法中的哪一种,相对于根来说( /index.html )在您的基础上最好,因为它会始终将您带回索引 - 您可以将 example.html 添加到与index相同的文件夹,甚至是 pages 的子文件夹,在这种情况下,第二个相关链接将需要修改。如果你在多个页面上有这样的链接,这可能会令人讨厌;)



为了进一步阅读相对和绝对URL,我建议查看咖啡杯文章



<希望这有助于! :)

In my website, I have an html file inside of a folder, that is next to the index file. I want to add a link back to the index file.

For example, the URL for the index would be, example.com. The 2nd page is example.com/pages/example.html. How would i send the user back to the index page?

解决方案

Assuming you have the following structure:

website.com/index.html
website.com/pages/example.html

You have three options -- two relative links, and one absolute link:

Relative to example.html:

<a href="../index.html">Back to the index</a>

Relative to the root (note the slash):

<a href="/index.html">Back to the index</a>

Absolute:

<a href="http://example.com/index.html">Back to the index</a>

I'd recommend using a relative root, as your website URL may change in the future, so you don't really want to hardcode it.

As for which of the two relative approaches to use, relative to the root (/index.html) would be best in your base, as it will always take you back to the index -- you may move example.html to the same folder as index, or even a subfolder of pages, in which case the second relative link would need modification. If you have that link in multiple pages, that could prove annoying ;)

For further reading on relative and absolute URLs, I recommend checking out the Coffee Cup article.

Hope this helps! :)

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

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