开发者

location.href in javascript?

javascript:

  1. location.href("somefile.php"); // successfully working with IE
  2. 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,


  1. href is not a method, it is a property whose value is a string.
  2. 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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜