最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - open multiple webpages in same tab - Stack Overflow

programmeradmin1浏览0评论

Have multiple hyperlinks in a report, everytime a click on a hyperlink the webpage opens in a new tab, Is it possible to open the hyperlinks in only one tab instead of multiple tabs using javascript ? Please help

I am currently using window.open to open the webpages, I cannot use target. Below is the code :

    I basically have a jqgrid where all the values of a column have hyperlink,

    if (GridColNum == 2) //index of the column
    {
    localStorage.valuekey = $('#filters_grid').jqGrid('getCell', GridRowId, 1);
    window.open(''); 
    }

And i am using the clicked value in another page using localstorage feature

Have multiple hyperlinks in a report, everytime a click on a hyperlink the webpage opens in a new tab, Is it possible to open the hyperlinks in only one tab instead of multiple tabs using javascript ? Please help

I am currently using window.open to open the webpages, I cannot use target. Below is the code :

    I basically have a jqgrid where all the values of a column have hyperlink,

    if (GridColNum == 2) //index of the column
    {
    localStorage.valuekey = $('#filters_grid').jqGrid('getCell', GridRowId, 1);
    window.open('http://mywebpage.html'); 
    }

And i am using the clicked value in another page using localstorage feature

Share Improve this question edited May 31, 2013 at 15:28 Suri asked May 31, 2013 at 13:41 SuriSuri 211 silver badge3 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 9

Yes, it's possible. Use syntax

<a href="..." target="rptTab"/>

for all relevant links. This way the first time a link is clicked a new tab will be opened; for subsequent clicks, that tab will be reused.

EDIT: if you're opening the link in javascript using window.open, then you need to specify the name of the tab/window as the second parameter:

window.open('http://mywebpage.html', 'rptTab');

You probably have a target='_blank' attribute in your links. Just remove them. If that does not help please post some code so we can see what is happening

When you specify the target of a window.open() call or an tag, you can specify _blank, _parent, _self or _top, as special tab/window names. Alternatively you can specify a new tab/window name, when you specify this tab/window another time, it will refer to the original one that you opened.

hyperlinks opens a new browser tab - is due to

target='_blank'

attribute of it. you can remove it using following jQuery code.

$('a').removeAttr('target');

now on-wards every link will get open in the same page.

You don't need javascript for this. Just use the target-attribute of the a tag. All links with the same target should be opened in the same tab.

http://www.w3schools./tags/att_a_target.asp

发布评论

评论列表(0)

  1. 暂无评论