window.location的刷新,而不是重定向 [英] Window.Location Refreshes instead of Redirects

查看:334
本文介绍了window.location的刷新,而不是重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery函数如下:

I have a JQUERY function as follows

this.getURL = function()
{
    var name = getName();
    alert("Menu.aspx?name"+name);
    //window.location = "Menu.aspx?name"+name;
}

当我提醒我试图去的URL,这是正确的。然而,当我打电话了window.location该字符串,页面只是刷新没有去任何地方。

When I alert the URL I am attempting to go to, it is correct. However, when I call window.location on that string, the page just refreshes without going anywhere.

我也有类似code,其中我已经用了window.location和它的作品。我在url到我的浏览器类型和它的作品也是如此。

I have similar code where I have used window.location and it works. I typed in the url into my browser and it works as well.

在最坏的情况(即使该URL是错误的),我希望它只是重定向我到某些URL。但是,我不能让它做多刷新当前页面的任何其他。

At worst (even if the URL was wrong), I was hoping that it would just redirect me to some URL. However, I can't get it to do anything other than refresh the current page.

另外要澄清一下,调用该函数的页面是不是Menu.aspx

Also to clarify, the page which calls this function is not Menu.aspx

先谢谢了。

推荐答案

如果您使用的是相对路径尝试设置 window.location.pathname ,否则设置 window.location.href 的完整路径。

If you're using a relative path try setting window.location.pathname, otherwise set window.location.href for a full path.

您也可以尝试 self.location.href

这篇关于window.location的刷新,而不是重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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