如何使用 window.open() 快速访问我的网站的根目录?

Yon*_*nic 3 html javascript url window.open

假设我的网站中有一个页面:

  • mywebiste.com/section1/slideshow/main/example.html

我想用来window.open()访问我网站中的这些页面:

  • mywebsite.com/section2/index.html
  • mywebsite.com/section2/article1/gallery.html
  • mywebsite.com/login.php

这些只是随机的示例,但我试图指出它们距离页面非常远example.html,我将不得不使用大量的../和 因此最终会得到非常长(且令人困惑)的URL。

我认为应该有一种方法可以直接访问网站的根目录,但仍然使用相对URL。(就像如果存在快捷方式.../或root/可以将您重定向到根目录)。

这可能吗?

Nea*_*eal 5

/ 只是以一个应该工作作为序言。

window.open('/section2/index.html', ...); // etc
Run Code Online (Sandbox Code Playgroud)