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
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();
}
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
<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. sajad-lfc gave the rigth answer.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.