2012-06-25 36 views

Trả lời

4

tôi có thể khẳng định điều này (Phiên bản 6.0 (8536,25)). Dường như là một lỗi Safari, theo như tôi có thể nói.

Thử nghiệm trên jsbin (http://jsbin.com/enugoj/1/):

console.log(window.location); 
console.log(window.location.pathname);​ 

Kết quả trong giao diện điều khiển của Safari:

Location 
    ancestorOrigins: undefined 
    hash: undefined 
    host: undefined 
    hostname: undefined 
    href: undefined 
    origin: undefined 
    pathname: undefined 
    port: undefined 
    protocol: undefined 
    search: undefined 
    __proto__: LocationPrototype 

/enugoj/1 

Kết quả trong Chrome (Phiên bản 21.0.1180.89) :

Location 
    ancestorOrigins: DOMStringList 
    assign: function() { [native code] } 
    hash: "" 
    host: "jsbin.com" 
    hostname: "jsbin.com" 
    href: "http://jsbin.com/enugoj/1" 
    origin: "http://jsbin.com" 
    pathname: "/enugoj/1" 
    port: "" 
    protocol: "http:" 
    reload: function() { [native code] } 
    replace: function() { [native code] } 
    search: "" 
    toString: function toString() { [native code] } 
    valueOf: function valueOf() { [native code] } 
    __proto__: Location 
    1:14 

/enugoj/1 
+1

Đúng là chính xác những gì tôi nhận được ... tất cả undefined :( –

5

mã này hoạt động trong Safari (6.0.1) và trước đó

// Get location for REST TARGETS 

    lcnURI = window.location.protocol + "//" + window.location.hostname + ":" 
      + window.location.port + "/rest/"; 

Có vẻ như window.location "nằm ngoài ngữ cảnh" khi bạn xem trong nhật ký. Nhưng tại chỗ sử dụng nó là tốt.

+0

Điều tôi đang mong đợi tất cả các thuộc tính của đối tượng vị trí, không chỉ là URI. –

Các vấn đề liên quan