Skip to content Skip to sidebar Skip to footer

How To Open Url To The Same Tab If Its Already Open In Browser

I am facing some challenge- Lets consider I have a menu and under that I have 3 links- About Contact Us FAQs By default home page is About menu item. Now when I am clicking on 'Co

Solution 1:

you can always put a name in the target so it will always go to the same window/tab

<ahref="somerandomurl.com"target="mywindow">Contact Us<\a>

Its not possible to control this on Internet explorer. You can however change how IE behaves: -Internet Options -Tabs -Always open pop-ups in a new tab -Open links from other programs in: A new tab in the current window

target="_blank" will always make sure it opens in a new window http://www.w3schools.com/tags/att_a_target.asp

It will however refresh the page with the same url

You can have the link return a javascript window object and be able to return to the window anytime you want without refreshing the page

var newtab = null;

functionopenwindow(){
  if (newtab==null) {
    newtab = window.open("www.example.com");
  } else {
    newtab.focus();
  }

}
<aonclick="openwindow()">click me</a>

Solution 2:

This solution will work if someone refresh the parent page also, it will close the child tab if that tab is already open on refresh of parent page. Javascript:

<script>var newtab = null;
        window.open('', 'business-list', '').close();
        functionopenwindow() {
            if (!newtab || newtab.closed) {
                newtab = window.open("/admin/business-list.aspx","business-list");
            } else {
                newtab.focus();
            }

        }
    </script>

HTML:

<aonclick="openwindow()"style="cursor:pointer">Business List</a>

Post a Comment for "How To Open Url To The Same Tab If Its Already Open In Browser"