title: How to Properly Use this in External Javascript?
body: <p>I have two javascript functions that work fine so long as I keep them in the HTML of my head tag, but I'd like to move them to an external javascript file.</p>
  
  <pre><code>function uploadImageSB() {
  
      Shadowbox.init({});
  
      // shadowbox for image upload
      Shadowbox.open({
  
          content: 'photo.cgi?function=photo_upload',
          player: 'iframe',
          title: 'Image Upload',
          height: 200,
          width: 500,
          options: {
  
              onFinish: function () {
  
                  // get the iframe
                  var iframe = document.getElementById('sb-player');
  
                  var formName = 'photoForm';
  
                  // add an event listener to determine when the sb form is fully loaded
                  if (iframe.addEventListener) {
                      // use addEventListener for Safari, Chrome, Firefox
                      iframe.addEventListener("load", getTA(formName), true);
                  } else {
                      // use attachEvent for IE
                      iframe.attachEvent("onload", getTA(formName));
                  }
              }
          }
      })
  };
  </code></pre>
  
  <p>The above javascript calls this next function:</p>
  
  <pre><code>function getTA(fn) {
  
      // get the contents of the tinymce editor
      var ed = tinymce.activeEditor;
      var content = ed.save();
  
      // dynamically create textarea
      var ta = document.createElement('textarea');
      ta.textContent = content;
      ta.name = 'article';
      ta.value = ta.textContent;
  
      // get the iframe content
      var iframeContent = this.contentDocument || this.contentWindow.document;
  
      // append the textarea to the shadowbox form, but do not display it
      var form = iframeContent.getElementById(fn);
      form.appendChild(ta);
      form.getElementsByTagName('textarea')[0].style.display = 'none';
  };
  </code></pre>
  
  <p>I think the problem is with my usage of <code>this</code> here:</p>
  
  <pre><code>var iframeContent = this.contentDocument || this.contentWindow.document;
  </code></pre>
  
  <p>But I'm not sure how fix it. thanks.</p>