我如何将用户从一个页面转向另一个页面,使用jQuery或纯粹的JavaScript?


当前回答

这就是我如何使用它。

   window.location.replace('yourPage.aspx');   
   // If you're on root and redirection page is also on the root

   window.location.replace(window.location.host + '/subDirectory/yourPage.aspx');

   // If you're in sub directory and redirection page is also in some other sub directory.

其他回答

在JavaScript和jQuery中,我们可以使用以下代码将一页转向另一页:

window.location.href="http://google.com";
window.location.replace("page1.html");

这就是我如何使用它。

   window.location.replace('yourPage.aspx');   
   // If you're on root and redirection page is also on the root

   window.location.replace(window.location.host + '/subDirectory/yourPage.aspx');

   // If you're in sub directory and redirection page is also in some other sub directory.
<script type="text/javascript">
    if(window.location.href === "http://stackoverflow.com") {      
         window.location.replace("https://www.google.co.in/");
       }
</script>

在 PHP、HTML 或 jQuery 部分后写下下面的代码,如果在 PHP 或 HTML 部分中间,则使用 <script> 标签。

location.href = "http://google.com"

使用:

function redirect(a) {
    location = a
}

求主引导他,求主引导他。

没有必要在位置后进行Href,因为它是有意义的。