1

单击页面中的链接时,我试图重用相同的选项卡。链接是从数据库中动态获取的。我已经尝试window.open("$LinkURL", "MyTab");假设$LinkURL是我要打开的链接的变量。但是,当单击链接时,每次都会在新选项卡中打开。

我注意到的是,如果新标签仍在加载,我可以重复使用我的标签。但是,一旦加载,我会打开一个新标签,然后有 2 个标签。第二件事是,如果我使用(http://www.google.com/)作为打开的 URL 而不是$LinkURL变量,它会按预期工作,并且每次单击新链接时我都可以重用相同的选项卡。这是我正在使用的代码示例:

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>
4

1 回答 1

0

代替window.open,您可以使用location.href,这样:

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

或者,如果我不理解这个问题,并且您希望它们始终在一个新的相同窗口中打开,您可以这样做:

<a href="theLink" id="LinkId_" target="newTab">
    <img src="game/castleville/image/'.$ItemInfo_cat_img.'" name="'.$ItemInfo_cat_type.'" />
</a>
于 2013-03-03T20:41:38.907 回答