location.href in javascript?
javascript:
- location.href("somefile.php"); // successfully working with IE
- location.href = "somefile.php";
Ques 1. first code is not work with Safari. Why?
Ques 2. What is the difference b/w th开发者_运维技巧ese codes.Thanks,
href
is not a method, it is a property whose value is a string.- The first is a call on a method with a url as the argument (incorrect), the second is assigning the url as the value of the property (correct).
See also: http://www.w3.org/TR/Window/#location
i never heard of location.href("somefile.php");
... location.href = "somefile.php";
is the "normal" way that you should use.
Also it's more efficient using window.location than location. So try to use :
window.location.href = "somefile.php";
(as Andy said, href is a property and in JS you specify a property value in this way: object.property = "value")
Answer 1 :- It wont work because href is a property of location object, not a method.
Answer 2 :- location.href("...") denotes a method(that is invalid) while location.href is a property.
精彩评论