1

I am trying to reuse the same tab when clicking on links in my page. The links are grabbed dynamically from the database. I have tried the window.open("$LinkURL", "MyTab"); assuming that the $LinkURL is the varriable with the link I want to open. But when a link is clicked, it opens in a new tab each time.

What I have noticed is that I can get my Tab to be reused if the new tab was still loading. But, once loaded I get a new tab opened and then have 2 tabs. the second thing is that if I use (http://www.google.com/) as the URL to open instead of the $LinkURL varriable it works as expected and I am able to reuse the same Tab each time I click a new link. Here is a sample of the code I am using:

function newwin (urllink) { newwindow = window.open( urllink ,'newwin'); //this is for closing the tab after some seconds, but i deactivate it for now //window.setInterval(function(){window.newwindow.close()},10500); } 
<a href="javascript:newwin(\''.trim($CvITem_referal_link).'\');" id="LinkId_'.$J.'"> <img src="game/castleville/image/'.$ItemInfo_cat_img.'" name="'.$ItemInfo_cat_type.'" /> </a> 
2

1 Answer 1

0

Instead of window.open, you can use location.href, this way:

function newwin (urllink) { location.href = urllink; } 

Or if I didn't understand the question, and you wanted them to open in a one new and the same window always, you can do this way:

<a href="theLink" id="LinkId_" target="newTab"> <img src="game/castleville/image/'.$ItemInfo_cat_img.'" name="'.$ItemInfo_cat_type.'" /> </a> 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer Praveen Kumar. in fact i wanted the links to be opened in a new tab but i wanted the tab to be reused each time i click a new link. and if there was no tab opened yet we open it for the first time then keep reusing it every time we clicked a link. I tried the the two scripts but no way; the first opened the link inside the current and active tab and the second kept opening new tab each time a link was clicked. => I want only one tab opened and keeping reused.
@user2129653 The second one is supposed to open a new window on the first click and subsequent clicks should go to the same new window.
tahnks again for replying;yes i totally agree with you that's right it will open new tab and continue reusing it... but not in my page I managed to close the opened tab before opening a new one ;) that's tip i am using for now. But the problem now if that i want to set the focus to the original window but couldn't een if i am using window.focus(); method ... have you any idea about that??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.