需要以下代码才能打开新选项卡,而不是在当前选项卡中打开

时间:2017-03-12 07:55:52

标签: html onclick

我需要在新标签页中打开以下代码。该链接指向一个由" Occupation Link 1"指定的网站。

{block:ifOccupation1}
    <a {block:ifOccupationlink1}onclick="window.location.href='{text:Occupation Link 1}'" style="cursor:pointer"{/block:ifOccupationlink1}>
        {text:Occupation 1}
    </a>
    {/block:ifOccupation1}

2 个答案:

答案 0 :(得分:1)

?target=_blank添加到网址末尾:

{block:ifOccupation1}
    <a {block:ifOccupationlink1}onclick="window.location.href='{text:Occupation Link 1}'" target='_blank' style="cursor:pointer"{/block:ifOccupationlink1}>
        {text:Occupation 1}
    </a>
{/block:ifOccupation1}

答案 1 :(得分:1)

要在新标签中打开链接,您只需在锚标记中添加一个目标,即target =“_ blank”。这个'_blank'实际上在新标签页中打开了所需的链接。

**<a {block:ifOccupationlink1}onclick="window.location.href='{text:Occupation Link 1}'" target="_blank" style="cursor:pointer"{/block:ifOccupationlink1}>
    {text:Occupation 1}
</a>**