Posted By

1man on 03/08/07


Tagged

javascript window standard DOM open new


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

basicmagic
cynic68
vali29
jonhenshaw
gAmUssA
cldwntrsdy
guo3823538


Standard Compliant Way to Open A New Page Function


 / Published in: JavaScript
 

This function allows you to open a new window, without using any inline Javascript. Simply add rel="external" to the link you wish to open in a new window.

  1. function doStandardsCompliantExternalLinks() {
  2. if (!document.getElementsByTagName) {return;}
  3. var anchors = document.getElementsByTagName("a");
  4. for (var i=0; i<anchors.length; i++) {
  5. if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external") {// for example: title="Download Adobe Reader" rel="external"
  6. anchors[i].target = "_blank";
  7. anchors[i].title += " - Opens in new window";
  8. }
  9. }
  10. }

Report this snippet  

You need to login to post a comment.