1

I am trying to open a new tab using JavaScript and then I want to get the url of the newly opened tab. I did some research and figured out it is something related to parent (current tab) and child (newly opened) tab communication.

I am able to open the new tab using the script:

 url='https://www.google.com/'+home;
 window.open(url, '_blank');

I want to get the url of my newly opened tab here in this script as you can see i have opened /home so it change the new url to https://store.google.com/magazine/compare_nest_speakers_displays?srp=/product/google_home. I want to get that new url in my script.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • `location.href` is the way you get url but i really couldn't understand question i think. – halilcakar Jun 06 '20 at 16:57
  • ```location.href``` is to the url of current tab I want to get the url of tab opened by window.open – Gaurav Sachdeva Jun 06 '20 at 17:06
  • Oh yea obv i didn't understand it correctly :D – halilcakar Jun 06 '20 at 17:06
  • So basically I have opened a new tab using window.open and it opened a new tab... I want to get that url of the new tab – Gaurav Sachdeva Jun 06 '20 at 17:20
  • Isn't that already `url` variable ? =) – halilcakar Jun 06 '20 at 17:27
  • But it get changed after you run it! so from 'https://www.google.com/home' when it opens it changes the url to '"https://store.google.com/magazine/compare_nest_speakers_displays?srp=/product/google_home' something like this... I want that url – Gaurav Sachdeva Jun 06 '20 at 17:45
  • Ohh i got it now, as far as i understand u need to redirected url right? If this is the i don't know that much but you might check https://stackoverflow.com/questions/37603335/how-to-get-the-redirected-url-in-javascript this – halilcakar Jun 06 '20 at 17:50
  • 1
    Think about this; would you expect the browser API would give one site the ability to spy on which pages a user is visiting in another tab? That's why protections exist so you _can't_ do things like this. – Jacob Jun 06 '20 at 18:40

0 Answers0