开发者

Which browsers don't support location.href and how to process this?

I have a situation where a PC user's b开发者_StackOverflowrowser (I don't know which browser is it) doesn't have support for location.href, http://www.w3schools.com/jsref/prop_loc_href.asp.

JavaScript is on. Cause fancyBox shows up login popup, which result is - location.href change to ./admin.php?act=loggedok (as example)

Can anybody tell me how to detect this and how to process this issue?

Is this possible to lock out this JS code?

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


the location object of the navigator is supported everywhere.. what you can do is to make a simple check if location is arround and then react to it as you need..

if ( window.location){ //or if (location in window) for modern browsers..
    window.location.href="www.google.com";
}
else{
    alert("please enter www.google.com into your address bar"); // :P
}

Btw; in a noscript tag, you cant do any javascript, so you cant "react to the user having javascript off". But you can display additional html in such a way, that shows the user he still lives in the 90's and should update his IE3 and enable javascript ;)


You need to be sure that Javascript support in user's browser is turned on. As you can see on w3schools web site it is supported by all main browsers.

This link can help: Mozilla: location


why don't you use

document.location.href = 'http://google.com/';

instead?

It works on all browsers unless they have javascript disabled


The problem is either that javascript is not supported, turned off, or the browser does not support the location object which is basically shorthand for window.location. thus use:

window.location.href="http://www.google.com";


As Andron said all major browsers should support it unless they specifically have javascript disabled. You can tell the user about this using the <noscript> tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜