0

It's very easy to open two URL one by one by using interval but in the same tab.

e.g.

<div ng-click="openTwoUrl()">Click Me</div>

JS:

$scope.openTwoUrl=function(){
    $window.location.href='www.linkone.com';

    //Below will wait for the above link to be fully loaded.
    var interval = setInterval(function() {
        if(document.readyState === 'complete') {
            $window.location.href='linktwo.com';
            clearInterval(interval);
        }    
    }, 100);
}

But my requirement is that I want to open these URL to be open one by one in a new tab.

So to open a new tab I use $window.open('www.firstlink.com') and immediately a new tab is opened and now I want that in that newly opened tab my second URL i.e www.secondlink.com to be loaded.

Searched a lot but didn't found anything. Any help or suggestion would be greatly appreciated.

NOTE:

JavaScript: location.href to open in new window/tab?

This question doesn't give me the solution to my problem

Tk1993
  • 501
  • 8
  • 21
  • 1
    Have you tried var win = window.open(url, '_blank'); win.focus(); – Davesoft Jul 19 '18 at 14:06
  • 2
    Possible duplicate of [JavaScript: location.href to open in new window/tab?](https://stackoverflow.com/questions/5141910/javascript-location-href-to-open-in-new-window-tab) – mcarton Jul 19 '18 at 22:42
  • @mcarton how it can be a duplicate? My question is asking to open two urls one by one in a new tab. But your posted question is telling how to simply open a singe url in a new tab – Tk1993 Jul 20 '18 at 07:42
  • @Davesoft if you can explain more about it, that would be great – Tk1993 Jul 20 '18 at 08:37

1 Answers1

1

I don't think this is possible in pure javascript unless you are writing a chrome extension of some sort.

You would need to pass javascript from one tab to the other. That would require cross site-scripting which is a security vulnerability! Websites would never allow that.

Joseph Cho
  • 4,033
  • 4
  • 26
  • 33