To define a name in the target
attribute, you can do the following:
<asp:HyperLink
NavigateUrl="https://www.google.com"
Text="Go to Google"
Target="SameWindow"
runat="server"/>
<asp:HyperLink
NavigateUrl="http://stackoverflow.com"
Text="Go to StackOverflow"
Target="SameWindow"
runat="server"/>
HTML example:
<a href="http://www.google.com" target="SameWindow">Go to Google</a>
<br />
<a href="http://stackoverflow.com" target="SameWindow">Go to StackOverflow</a>
This method is similar to using the JavaScript window.open
function to assign a name to a window. Once a named window is opened, subsequent calls to window.open
with that name specified will load the new URL in the existing window.
Below is a example snippet. Please run this code in a full JSFiddle page due to security limitations (CORS).
var openTarget = function() {
console.log(this);
var target = this.getAttribute("attr-target");
window.open(target, "ExampleName");
}
var elems = document.querySelectorAll("button");
Array.prototype.forEach.call(elems, function(e) {
e.addEventListener("click", openTarget);
});
<button attr-target="https://www.google.com/">Open Google</button>
<button attr-target="http://stackoverflow.com/">Open StackOverflow</button>