Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 "Contact Us" , I want to open a new tab on same browser window. And without closing this if again I am clinking on "Contact Us" from the first tab, this time I do not want to open new tab because I have already an open tab for Contact us, I just wanted to navigate to the same one which is earlier opened. How to handle this scenario in jsp.

Is there any way to do this. please help me.

like image 215
Avhi Avatar asked Feb 08 '23 05:02

Avhi


1 Answers

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

<a href="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;

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

}
<a onclick="openwindow()">click me</a>
like image 100
Enfantcool Avatar answered Apr 25 '23 20:04

Enfantcool