如何使用javascript进行相对路径重定向? [英] how to do a relative path redirection using javascript?
问题描述
我正在基于php的站点中使用javascript/jquery,并且必须在页面中发生事件时重定向页面.
I'm working on javascript/jquery in a php based site, and I have to redirect the page upon an event in the page.
可以说,单击"page1.php"
中的单击我"按钮时,页面应重定向到"page2.php
".这种重定向必须使用javascript/jquery完成.两个页面都在同一个文件夹中,重定向代码应使用'RELATIVE LINKS'.
lets say, on clicking the button "click me" in "page1.php"
, the page should be redirected to "page2.php
". This redirection has to be done using javascript/ jquery. Both pages are in the same folder, and the redirection code should use 'RELATIVE LINKS'.
现在,如果我提供指向page2.php
的绝对链接,我可以重定向,但是有人可以让我知道如何使用相对链接吗?
Now, I am able to redirect if I give the absolute link to page2.php
, but could someone let me know how to do the same with a relative link?
类似:
window.location.href = 'page2.php';
谢谢.
推荐答案
window.location.href = "page2.php";
这有效.实际上,相对和绝对的工作方式相同:
this worked. Infact, relative and absolute works in the same way:
window.location.href = "http://www.google.com";
// or
window.location.href = "page2.html";
这篇关于如何使用javascript进行相对路径重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!