JQuery / javascript url search not working

I am trying to get this full URL: https://mail.google.com/mail/u/0/?ui=2#inbox/13047asdee8be4e1

Using:

var url = document.location.toString();

But it only returns to https://mail.google.com/mail/u/0/?ui=2

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

+3
source share
5 answers

Give it a try window.location.href. Read this: window.location - MDC

Run this in the console to make 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();

: , , , :) . , , :)

+3

window.location.hash, #.

window.location + '#' + window.location.hash

window.location.href

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

document.location.hrefseems to work too, and in my test returned the entire address bar.

+6
source

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

+3
source

You do not need jQuery for this. You just need to add the hash to and your URL. Something like this should work.

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

0
source

All Articles