1

Is it possible?

So I have a link:

<a href='/page.htm' target='_blank'>

If they click it twice, it will load up two blank tabs. Is there anyway to get this particular link to load in the same new tab each time?

Chud37
  • 4,907
  • 13
  • 64
  • 116

2 Answers2

2

I would use window.open to reuse window if opened, you can see this answer for further details:

open url in new tab or reuse existing one whenever possible

Community
  • 1
  • 1
Robert
  • 3,276
  • 1
  • 17
  • 26
0

You can assign an onclick handler to the anchor that calls the open method of the window object. The first time the anchor is clicked, it opens a new browsing tab.

Notice the second parameter to the open method (i.e., "other-window"). This is a handle to the new tab. If you want to load new content into that tab (instead of opening yet another tab), just call the open method again with that same handle as the second parameter:

(function () {

    var childWindowOpen = false;

    window.onload = function (event) {
        var anchor = document.getElementById("child-window-link");

        anchor.onclick = function (event) {
            var childWindow;

            if (!childWindowOpen) {
                childWindow = window.open("otherpage.html", "other-window");
            } else {
                childWindow = window.open("yetanotherpage.html", "other-window");
            }
            childWindowOpen = true;
            return false;
        }
    };
}());
orb
  • 1,263
  • 1
  • 10
  • 16