windows .location.href(var)在ff7上的奇怪行为

window.location.href(var) strange behaviour on ff7

本文关键字:ff7 href location var windows      更新时间:2023-09-26

我不明白FF7的问题

我有一个ajax调用返回一个json对象(jquery)。

if(data.result=='ok') {
    var url = baseURL + "azioni/makeForm/" + data.actcode + "/DIA/" + data.az_id;
    console.log(url);
    window.location.href(url);
}

不工作,但这个可以:

if(data.result=='ok') {
    var url = baseURL + "azioni/makeForm/" + data.actcode + "/DIA/" + data.az_id;
    console.log(url);
    window.location.href = 'http://www.google.com/';
    window.location.href(url);
}

为什么?

请注意console.log工作完美并输出正确的url!

不妨试试:

if(data.result=='ok') {
                 var url = baseURL+"azioni/makeForm/"+data.actcode+"/DIA/"+data.az_id;console.log(url);
                window.location.href = url;
            }

也许你想使用:

document.location.href = url;

我认为。href不是一个方法,而是一个属性,所以你只能给它赋值。下面可能是一个事件侦听器,让浏览器重定向到该位置。

window.location.href不是函数。在你的第二个例子中,你可以简单地删除window.location.href(url),它会工作

window.location.href是一个JavaScript属性,而不是一个jQuery方法。要更改url,您应该使用=:

设置window.location
window.location = url;

参见https://developer.mozilla.org/en/window.location