简体   繁体   English

如何链接相同或不同文件夹中的html页面?

[英]How to link html pages in same or different folders?

如果它们位于相同或不同的文件夹中而不写完整路径,我如何链接到 html 页面?

Within the same folder, just use the file name:在同一个文件夹中,只需使用文件名:

<a href="thefile.html">my link</a>

Within the parent folder's directory:在父文件夹的目录中:

<a href="../thefile.html">my link</a>

Within a sub-directory:在子目录中:

<a href="subdir/thefile.html">my link</a>

In addition, if you want to refer to the root directory, you can use:另外,如果要引用根目录,可以使用:

/

Which will refer to the root.这将指的是根。 So, let's say we're in a file that's nested within a few levels of folders and you want to go back to the main index.html:因此,假设我们在一个嵌套在几级文件夹中的文件中,并且您想返回到主 index.html:

<a href="/index.html">My Index Page</a>

Robert is spot-on with further relative path explanations.罗伯特对进一步的相对路径解释很到位。

Also, this will go up a directory and then back down to another subfolder.此外,这将上升到一个目录,然后返回到另一个子文件夹。

<a href = "../subfolder/page.html">link</a>

To go up multiple directories you can do this.要上多个目录,您可以执行此操作。

<a href = "../../page.html">link</a>

To go the root, I use this去根,我用这个

<a href = "~/page.html">link</a>

You can go up a folder in the hierarchy by using您可以使用

../

So to get to folder /webroot/site/pages/folder2/mypage.htm from /webroot/site/pages/folder1/myotherpage.htm your link would look like this:因此,要从 /webroot/site/pages/folder1/myotherpage.htm 访问文件夹 /webroot/site/pages/folder2/mypage.htm,您的链接将如下所示:

<a href="../folder2/mypage.htm">Link to My Page</a>

use the relative path使用相对路径

main page might be: /index.html主页可能是: /index.html

secondary page: /otherFolder/otherpage.html二级页面: /otherFolder/otherpage.html

link would be like so:链接是这样的:

<a href="/otherFolder/otherpage.html">otherpage</a>

If you'd like to link to the root directory you can use如果你想链接到根目录,你可以使用

/ , or /index.html / , 或/index.html

If you'd like to link to a file in the same directory, simply put the file name如果您想链接到同一目录中的文件,只需输入文件名

<a href="/employees.html">Employees Click Here</a>

To move back a folder, you can use要移回文件夹,您可以使用

../

To link to the index page in the employees directory from the root directory, you'd do this要从根目录链接到员工目录中的索引页面,您可以这样做

<a href="../employees/index.html">Employees Directory Index Page</a>

I would caution you: if you are using absolute paths, then your application cannot be installed in a "subdirectory" of the server!我要提醒您:如果您使用的是绝对路径,那么您的应用程序不能安装在服务器的“子目录”中!

eg, http://yourserver.com/yourapp may work, but http://myserver.com/apps/yourapp will not!例如, http : //yourserver.com/yourapp可能会起作用,但http://myserver.com/apps/yourapp不会!

Short answer:简短的回答:

. . is for current directory用于当前目录

.. is for upper directory as in cd .. command on shell. ..用于上层目录,如 shell 上的cd ..命令。

Simple yet tricky, I write this answer primarily for myself not to forget next time.简单而棘手,我写这个答案主要是为了自己下次不要忘记。

ademSite/
├── index.html
└── style.css

The link to CSS in index.html : index.html CSS的链接:

<link rel="stylesheet" href="style.css"> or <link rel="stylesheet" href="./style.css"> <link rel="stylesheet" href="style.css"><link rel="stylesheet" href="./style.css">

ademSite/
├── index.html
└── stylefiles
    └── style.css

This case it should be:这种情况应该是:

<link rel="stylesheet" href="stylefiles/style.css"> or <link rel="stylesheet" href="./stylefiles/style.css"> <link rel="stylesheet" href="stylefiles/style.css"><link rel="stylesheet" href="./stylefiles/style.css">

├── html
│   └── index.html
└── stylefiles
    └── style.css

In this case path must be: <link rel="stylesheet" href="../stylefiles/style.css">在这种情况下,路径必须是: <link rel="stylesheet" href="../stylefiles/style.css">

Use采用

../

For example if your file, lets say image is in folder1 in folder2 you locate it this way例如,如果你的文件,可以说图像是在folder1folder2你找到它这样

../folder1/folder2/image

href="./page.htm" for the same directory href="./page.htm" 用于同一目录

href="../page.htm" parent directory href="../page.htm" 父目录

href="~/page.htm" root directory or the upper most dir. href="~/page.htm" 根目录或最上层目录。

Answer below is what I created to link html contents from another shared drive to the html page I would send out to managers.下面的答案是我创建的用于将另一个共享驱动器中的 html 内容链接到我将发送给经理的 html 页面的内容。 Of course, the path is relative to your using, but in my case, I would just send them the html, and everything else that is updated from load runner dynamically would be updated for me.当然,路径与您的使用有关,但在我的情况下,我只会向他们发送 html,而从负载运行器动态更新的所有其他内容都会为我更新。 Saves tons of paper, and they can play with the numbers as they see fit instead of just a hard copy this way.节省大量纸张,并且他们可以按照他们认为合适的方式玩数字,而不仅仅是这种方式的硬拷贝。

SRC="file://///shareddrive/shareddrive-folder/username/scripting/testReport\contents.html" NAME="contents_frame" title="Table of Contents"

For ASP.NET, this worked for me on development and deployment:对于 ASP.NET,这对我的开发和部署有用:

<a runat="server" href="~/Subfolder/TargetPage">TargetPage</a>

Using runat="server" and the href="~/" are the keys for going to the root.使用runat="server"href="~/"是进入根目录的关键。

这对我<a href="preferedfile name.html">to be clicked <a/>

When I Was creating a webpage, I found out that With moving Html files to different Folders, It changes the paths of the images, videos, music, PDF files, etc. With them, you have to go out of the file the HTML is located in, with the ../HTML .当我在创建网页时,我发现将 Html 文件移动到不同的文件夹,它会改变图像、视频、音乐、PDF 文件等的路径。有了它们,你必须走出 HTML 文件位于../HTML中。 Then when your out, depending on where your page content is, insert,然后当你出去的时候,根据你的页面内容在哪里,插入,

 <a href="Meme/WP/Chipmunk.html">Chipmunk Memes</a> */ This is where the HTML is located ^^^^^^ */ <img class="demo cursor" src="../6.png" width="100" height="50" onclick="currentSlide(6)" alt="Sasha Having Some Fun"> */ This is where the images are located. The "../6.png" is the image file, and it is located one directory back. */

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

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