Change hyperlink target : a link « HTML Tags « JavaScript Tutorial






<html>
<head>
<script language="JavaScript" type = "text/javascript">
<!--
function ChangeLink() {
    var newlink = document.getElementById("urltext");
    var curlink = document.getElementById("oldurl");
    curlink.href = ("http://" + newlink.value);
    curlink.innerHTML = newlink.value;
}

function NewWindow(prefval) {
    var curlink = document.getElementById("oldurl");
    if (prefval == 1)
    {
        curlink.setAttribute("target", "_blank");
    }
    else if (prefval == 2)
    {
        curlink.removeAttribute("target");
    }
}
//-->
</script>
</head>
<body>
<form>
<a id="oldurl" href="http://www.java2s.com">www.java2s.com</a>
<P><input type="radio" value="V1" name="R1" onClick="NewWindow(1)">Open in New Window</p>
<P><input type="radio" name="R1" checked value="V2" onClick="NewWindow(2)">Open in Same Window</p>
   <input type="text" id="urltext" size="20">&nbsp;
   <input type="button" value="Change Link" name="B3" onClick="ChangeLink()"></p>
</form>
</body>
</html>








21.1.a link
21.1.1.Link
21.1.2.Link.handleEvent()
21.1.3.Link.hash
21.1.4.Link.host
21.1.5.Link.hostname
21.1.6.Link.href
21.1.7.Link.onClick
21.1.8.Link.onDblClick
21.1.9.Link.onKeyDown
21.1.10.Link.onKeyPress
21.1.11.Link.onKeyUp
21.1.12.Link.onMouseDown
21.1.13.Link.onMouseOut
21.1.14.Link.onMouseOver
21.1.15.Link.onMouseUp
21.1.16.Link.pathname
21.1.17.Link.port
21.1.18.Link.protocol
21.1.19.Link.search
21.1.20.Link.target
21.1.21.Link.text
21.1.22.Call a function in hyperlink
21.1.23.Change links
21.1.24.Hyper link onClick event
21.1.25.Change hyperlink target
21.1.26.Hyper link onmouseover evnet: change window.location
21.1.27.Call your function in hyper link onMouseover event
21.1.28.Update window status bar in mouse over event for a hyper link element tag(IE)
21.1.29.Create a link with value in form controls