0

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

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.

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? thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
John
  • 3,965
  • 21
  • 77
  • 163

5 Answers5

3

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.

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

Open a URL in a new tab (and not a new window) using JavaScript

IF browser setting are default(tested for FF)

this will work Open new tab in same browser window

function openinnewTab() {
    var win = window.open("~/TermsAndConditions", '_blank');
    win.focus();
}
Community
  • 1
  • 1
Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51
2

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

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

function newwin(e) {

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

    }

or

     function newwin(e) {

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

        }

OR pure asp.net code

<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

Arda
  • 470
  • 5
  • 10
  • thank you for reply I have tried this exactly but get the error: Line: 155 Error: Unable to get property 'preventDefault' of undefined or null reference – John Dec 24 '13 at 10:04
  • – John Dec 24 '13 at 10:04
  • again thanks for taking the time to reply. when i click the link it is telling me Error: 'newwin' is undefined, also when the new tab loads the url is :'javascript: void(0)' – John Dec 24 '13 at 10:14
  • edited again. try last one you dont need javascript for that :) – Arda Dec 24 '13 at 10:15
1
<a href='JavaScript:newwin('<%=ResolveClientUrl("~/OrchardLocal/TermsAndConditions")%>');'  >

and

<script>
    function newwin(url) {
        window.open(url,'_blank');
    }
</script>
Sajad Karuthedath
  • 14,987
  • 4
  • 32
  • 49
0

One tab is for your href and the other for your onclick. sajad-lfc gave the rigth answer.

eternel7
  • 53
  • 7
0

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.

user2951753
  • 103
  • 1
  • 3
  • 13