|
Sometimes you have content which contains Anchor Tag (A) and you would like to open its Src attribute within a "new" window instead of opening it in the Same window. Script below will let you open all the Ancor tags with the "target=_blank" attribute in it.
< html xmlns="http://www.w3.org/1999/xhtml" >
< head>
<title>Untitled Page</title>
<script>
function openTarget() {
var getDiv = document.getElementById("selfing")
var getDivA = getDiv.getElementsByTagName("a")
for(i=0; i<getDivA.length; i++) {
getDivA[i].target= "_blank"
}
}
</script>
</ head>
< body onload="openTarget()">
<form id="form1" runat="server">
<a href="http://www.msn.com">Same window</a>
<div id="selfing">
<a href="http://www.yahoo.com">New window</a><br />
<a href="http://www.yahoo.com">New window2</a>
</div>
</form>
</ body>
</ html>
Please note, Code above targets only a "DIV" name "selfing" within the entire page content.
|