Advertisement
Guest User

Untitled

a guest
May 5th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. {literal}
  2. <script type="text/javascript">
  3.  
  4. /***********************************************
  5. * Open select links in new window script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
  6. * This notice MUST stay intact for legal use
  7. * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
  8. ***********************************************/
  9.  
  10. /*****************USAGE NOTES:*****************
  11. Add: <form name="targetmain"><input type="checkbox" name="targetnew" checked onClick="applywindow(targetlinks)">Open designated links in new window</form>
  12.  
  13. anywhere on your page to automatically switch the script to manual mode, whereby only checking a checkbox will cause designated links to open in a new window. Customize the form as desired, but preserve key information such as the name attributes and onClick command. Remove form to switch back to auto mode.
  14. ***********************************************/
  15.  
  16. var linktarget="_blank" //Specify link target added to links when set to open in new window
  17.  
  18. var formcache=document.targetmain
  19.  
  20. function applywindow(){
  21. if (typeof targetlinks=="undefined") return
  22. if (!formcache || (formcache && formcache.targetnew.checked)){
  23. for (i=0; i<=(targetlinks.length-1); i++)
  24. targetlinks[i].target=linktarget
  25. }
  26. else
  27. for (i=0; i<=(targetlinks.length-1); i++)
  28. targetlinks[i].target=""
  29. }
  30.  
  31.  
  32. function collectElementbyClass(){
  33. if (!document.all && !document.getElementById) return
  34. var linksarray=new Array()
  35. var inc=0
  36. var alltags=document.all? document.all : document.getElementsByTagName("*")
  37. for (i=0; i<alltags.length; i++){
  38. if (alltags[i].className=="Link")
  39. linksarray[inc++]=alltags[i]
  40. if (alltags[i].className=="Message"){
  41. var alldivlinks=document.all? alltags[i].all.tags("A") : alltags[i].getElementsByTagName("A")
  42. for (t=0; t<alldivlinks.length; t++)
  43. linksarray[inc++]=alldivlinks[t]
  44. }
  45. }
  46. return linksarray
  47. }
  48. if (formcache && formcache.targetnew.checked) //overcome IE bug, manually check checkbox that has "checked" attribute
  49. setTimeout("document.targetmain.targetnew.checked=true",100)
  50. var targetlinks=collectElementbyClass()
  51. applywindow()
  52.  
  53. </script>
  54. {/literal}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement