简体   繁体   中英

URL attribute in document object of JavaScript

I have browsed google.com and checked the "URL" property of document object of JavaScript in browser console.

> documentNode = window["Document"]
       [object Function]
> obj = documentNode();
      [object XMLDocument]
> obj["URL"]
     "about:blank"

I am expecting google.com as the output, when I type obj["URL"] .

If my understanding is correct, Please let me know, why the above output says "about:blank"?

By executing obj = documentNode(); you are creating a new instance of a Document .

This means obj and window.document are both instances of Document , but they each have a unique instance with unique property values.

Try console.log(window.document.URL) - you should see the URL you were expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM