Jquery/Javascript检索URL不起作用

Nov*_*ero 3 javascript php url jquery gmail

我试图获得这个完整的网址:https://mail.google.com/mail/u/0/? ui = 2# inbox/ 13047asdee8be4e1

通过使用:

var url = document.location.toString();
Run Code Online (Sandbox Code Playgroud)

但它只返回到https://mail.google.com/mail/u/0/?ui=2

我也尝试过其他方法,比如document.url,window.location,它仍然会吐出同样的东西.

Ala*_*nse 6

尝试window.location.hash获取后的部分#.

然后你可以得到整个东西 window.location + '#' + window.location.hash

你也可以得到整个字符串 window.location.href


Fos*_*sco 6

var url = document.location.toString() + '#' + window.location.hash;
Run Code Online (Sandbox Code Playgroud)

document.location.href 似乎工作得很好,并在我的测试中返回整个地址栏.