replace target=_blank of anchor tag using javascrpt for w3c strict document type
JavaScript 8 Comments »If you are using strict mode as your html document type and if you have target=_blank in your html code then wc3 gives you an error. strict mode does not accept target=_blank and they suggest to use transitional mode.
here is the javascript replacement for target=_blank. before this you have to set the rel attribute of anchor tags to “external” or anything you wish because this is used in the javascript code so see which are all the anchor tags has set the rel attribute to external .
in other words you can set the rel attribute with some value to mean that these are the tags which has to be opened in a new window.
<script type="text/javascript"> function target_blank() { var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { if ((anchors[i].href!='') && anchors[i].rel == "external") anchors[i].target = "_blank"; } } window.onload = target_blank; </script> |
here is a script with which you can make a single anchor tag open in new window using javascript
<a href="some.html" onclick="window.open(this.href); return false;" onkeypress="window.open(this.href); return false;"> Open in new window using javascript</a> |
…
Recent Comments