John Jerrby John Jerrby - 1 month ago 5
Javascript Question

How to close tab without using window open

I use the following to open new tab (in new process) with some page content,

var p = document.getElementById("myElement");
var a = document.createElement('a');
a.setAttribute('href',".../mypage.html");
a.setAttribute('rel',"noreferrer");
a.setAttribute('target',"_blank");
p.appendChild(a);
a.click();


http://news.softpedia.com/news/Force-Google-Chrome-to-Open-Links-in-New-Processes-128962.shtml

When you use this code it always open new tab,
I want that when you call to this code it will see if it was a previous call that open in new tab,then it will close it and the new call will be opened in new tab.
or maybe to run the new page in the previous tab without close it.

I cannot use the regular window.open API's ...

Answer

Use the same technique as in my answer here . But instead of changing the the dom in the main window just call window.close(); Example

Comments