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>
blo0p3r
  • 6,790
  • 8
  • 49
  • 68
  • Find an answer here - http://stackoverflow.com/questions/10132833/opening-links-in-a-new-tab-and-only-the-new-tab?rq=1 – Roy Mar 03 '13 at 20:29
  • Or also an answer can be found here : http://stackoverflow.com/a/14345456/686036 – blo0p3r Mar 03 '13 at 20:40

1 Answers1

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>
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
  • 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. – Mohamed Amine Mar 03 '13 at 23:03
  • @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. – Praveen Kumar Purushothaman Mar 04 '13 at 05:13
  • 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?? – Mohamed Amine Mar 05 '13 at 01:33