简体   繁体   English

单击链接后,打开带有URL的选项卡

[英]Open a tab with a URL when link clicked

I want to open a new tab in the same browser when the 'Terms and Conditions' link is clicked which should return the URL: http://localH:30321/OrchardLocal/TermsAndConditions 单击“条款和条件”链接时,我想在同一浏览器中打开一个新标签,该链接应返回URL: http://localH:30321/OrchardLocal/TermsAndConditions

So Far I have: 到目前为止,我有:

<p>Accept the <a href="~/" target="_blank" onclick="newwin()"> <span class="big-red">Terms and Conditions</span></a></p>
<script>
    function newwin() {
        window.open("~/TermsAndConditions");
    }
</script>

This actually opens 2 new tabs in the same browser. 实际上,这会在同一浏览器中打开2个新标签页。

http://localH:30321/OrchardLocal/Users/Account/~/TermsAndConditions

which throws a page cannot be found for obvious reasons ad then the second tab shows the home page: 由于明显的原因,找不到引发页面的页面,然后第二个选项卡显示主页:

http://localH:30321/OrchardLocal/

Tried removing the href and one of the ~/...cant seem to get it...any help guys? 试图删除href和〜/ ... cant之一似乎可以得到它...任何帮助人员? thanks 谢谢

First of all sorry for the wrong answer: As you want to open the url in new tab of same browser Which is not possible.It all depends on the browser settings. 首先,对于错误的答案,我们深表歉意:由于您想在同一浏览器的新标签页中打开url,这是不可能的。这完全取决于浏览器的设置。

http://forums.asp.net/t/1902352.aspx http://forums.asp.net/t/1902352.aspx

Open a URL in a new tab (and not a new window) using JavaScript 使用JavaScript在新标签页(而不是新窗口)中打开URL

IF browser setting are default(tested for FF) 如果浏览器设置为默认设置(已测试FF)

this will work Open new tab in same browser window 这将起作用在同一浏览器窗口中打开新选项卡

function openinnewTab() {
    var win = window.open("~/TermsAndConditions", '_blank');
    win.focus();
}

try this 尝试这个

function newwin(e) {
    e.preventDefault();
    window.open("/TermsAndConditions", '_blank');
}

by the way you cant use directly "~" in javascript..if you want to use server code like this 顺便说一句,您不能在javascript ..中直接使用“〜”,如果要使用这样的服务器代码

function newwin(e) {
e.preventDefault();
window.open('<%= ResolveUrl("~/TermsAndConditions") %>', '_blank');
}

EDIT 编辑

<p>Accept the <a href="javascript: void(0)" target="_blank" onclick="newwin()"> <span class="big-red">Terms and Conditions</span></a></p>

JS JS

function newwin(e) {

    window.open('<%= ResolveUrl("~/TermsAndConditions") %>', '_blank');

    }

or 要么

     function newwin(e) {

            window.open("/TermsAndConditions", '_blank');

        }

OR pure asp.net code 或纯asp.net代码

<p>Accept the <a runat="server" href="~/TermsAndConditions" target="_blank" > <span class="big-red">Terms and Conditions</span></a></p>

you have to add runat="server" attribute 您必须添加runat =“ server”属性

<a href='JavaScript:newwin('<%=ResolveClientUrl("~/OrchardLocal/TermsAndConditions")%>');'  >

and

<script>
    function newwin(url) {
        window.open(url,'_blank');
    }
</script>

One tab is for your href and the other for your onclick. 一个选项卡用于您的href,另一个选项卡用于onclick。 sajad-lfc gave the rigth answer. sajad-lfc给出了正确的答案。

Try the following piece of code 尝试以下代码

<p>Accept the <a href="~/" target="_blank" onclick="newwin()"> <span class="big-red">Terms and Conditions</span></a></p>
<script>
    $("span.big-red").on("click", function () {
        window.open('www.yourdomain.com', '_blank');
    });
</script>

This is working perfectly hopefully works for you. 希望它能为您完美地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM