title: Javascript image open new window from bbcode
body: <p>Howdy I have this script</p>
  
  <pre><code>    var imageWindow;
  
  function bbCodeImage(){
  
      imageWindow.document.writeln('&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"');
      imageWindow.document.writeln('                        "http://www.w3.org/TR/html4/loose.dtd"&gt;');
      imageWindow.document.writeln('&lt;html&gt;');
      imageWindow.document.writeln('&lt;head&gt;');
      imageWindow.document.writeln('&lt;title&gt;'+link.getAttribute('imagedescription')+'&lt;/title&gt;');
      imageWindow.document.writeln('&lt;meta http-equiv="content-script-type" content="text/javascript"&gt;');
      imageWindow.document.writeln('&lt;meta http-equiv="content-style-type" content="text/css"&gt;');
      imageWindow.document.writeln('&lt;meta http-equiv="content-type" content="text/html;charset=iso-8859-1"&gt;');
      imageWindow.document.writeln('&lt;/head&gt;');
      imageWindow.document.writeln('&lt;body style="height:100%;margin:0;padding:0;text-align:center;overflow:hidden;"&gt;');
      imageWindow.document.writeln('&lt;div style="width:100%;height:100%;overflow:auto;"&gt;');
      imageWindow.document.writeln('  &lt;p style="margin:0;padding:0;"&gt;');
      imageWindow.document.writeln('    &lt;img src="'+link.href+'" alt="'+link.getAttribute('imagedescription')+'" style="margin:0 auto;" width="'+link.getAttribute('imagewidth')+'" height="'+link.getAttribute('imageheight')+'"&gt;');
      imageWindow.document.writeln('  &lt;/p&gt;');
      imageWindow.document.writeln('  &lt;p style="margin:0;padding:5px;"&gt;');
      imageWindow.document.writeln('    &lt;a href="#" onclick="window.close();"&gt;Close me.&lt;/a&gt;');
      imageWindow.document.writeln('  &lt;/p&gt;');
      imageWindow.document.writeln('&lt;/div&gt;');
      imageWindow.document.writeln('&lt;/body&gt;');
      imageWindow.document.writeln('&lt;/html&gt;');
      imageWindow.document.close();
  
      imageWindow.focus();
  
  }       // End of LbImage() function.
  
  
  
  var links=document.getElementsByTagName("a");
  
  function parsePage(){
  
    for(var n=0;n&lt;links.length;n++){
  
      if(links[n].getAttribute('windowheight') &amp;&amp; links[n].getAttribute('windowwidth') &amp;&amp; links[n].getAttribute('imageheight') &amp;&amp; links[n].getAttribute('imagewidth') &amp;&amp; links[n].getAttribute('imagedescription')){
  
  links[n].setAttribute('windowwidth',    Math.min(   parseInt(links[n].getAttribute('windowwidth')   ),screen.width-40)  );
  links[n].setAttribute('windowheight',   Math.min(   parseInt(links[n].getAttribute('windowheight')  ),screen.height-60) );
  
        links[n].onclick=function(){
          imageWindow=window.open('','newwin','resizable=1,width='+this.getAttribute('windowwidth')+',height='+this.getAttribute('windowheight'));
          writePopup(this);
          return false;
        }     // End of the function that is run onclick of a "pop-up link".
  
      }       // End if statement that checks link for a "pop-up link".
  
    }     // End for loop.
  
  }       // End of parsePage() function.
  </code></pre>
  
  <p>And I want to use it on my forum so that when a image is clicked it should open in a new window. The class/code in which the image is in is this </p>
  
  <pre><code>&lt;img src="http://domain.com/attachments/1365693541700-jpg.15/" alt="1365693541700.jpg" class="bbCodeImage LbImage" style=""&gt;
  </code></pre>
  
  <p>Is there any way I can get this to work with the bbcode on my forum?
  Thanks</p>