开发者

Jquery/Javascript Retrieval of URL Not Working

Im trying to get this complete url: https://mail.google.com/mail/u/0/?ui=2#inbox/13047asdee8be4e1

Through the use of:

var url = document.location.toString();

But it only retur开发者_如何学Pythonns up to https://mail.google.com/mail/u/0/?ui=2

I have also tried other ways like document.url, window.location and it still spits out same thing.


var url = document.location.toString() + '#' + window.location.hash;

document.location.href seemed to work as well and returned the entire address bar in my test.


Try window.location.hash to get the part after the #.

You can then get the entire thing with window.location + '#' + window.location.hash

You can also get the entire string with window.location.href


Try window.location.href. Read this: window.location - MDC

Run this in console to be sure.

function showLoc()
{
  var x = window.location;
  var t = ['Property - Typeof - Value',
            'window.location - ' + (typeof x) + ' - ' + x ];
  for (var prop in x){
    t.push(prop + ' - ' + (typeof x[prop]) + ' - ' +  (x[prop] || 'n/a'));
  }
  alert(t.join('\n'));
}
showLoc();

Disclaimer: This is the first time I am seeing all other answers wrong, except Jason :) So many good answers. Both describing how to go about solving it in a round about way and then showing the correct way as an afterthought :)


var url = window.location.href; should do it.


You don't need any jQuery for that. You'd simply need to append the hash at the and of your url. Something like this should work.

var url = document.location.toString() + "#" + window.location.hash;

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜