title: Creating a JSONP Callback From Safari Extension
body: <p>I'm trying to load some data from Reddit via a Safari extension.  I'm using a JSONP pattern to create the callback function and attach the new src to the script.  However, it looks like there are two window namespaces, and the function that I dynamically create is not available to the context of the dynamically added script.  </p>
  
  <p>This link seems to detail the problem for chrome, which I'm guessing is similar to mine in Safari.</p>
  
  <p><a href="https://stackoverflow.com/questions/8495825/jsonp-request-in-chrome-extension-callback-function-doesnt-exist">JSONP request in chrome extension, callback function doesn&#39;t exist?</a></p>
  
  <p>Here's the code (works outside of extension):</p>
  
  <pre><code>function jsonp(url, callback) {
      var callbackName = 'jsonp_callback_' + Math.round(100000 * Math.random());
      window[callbackName] = function(data) {
          delete window[callbackName];
          callback(data);
      };
      console.log('about to create script');
      var script = document.createElement('script');
      script.src = url + (url.indexOf('?') &gt;= 0 ? '&amp;' : '?') + 'jsonp=' + callbackName;
      document.body.appendChild(script);
      console.log('script should be appended');
  }
  
  
  function getImages(){
      jsonp('http://www.reddit.com/r/cats/.json', function(data) {
          data.data.children.forEach(function(el){
              console.log(el.data.url);
          });
      });    
  }
  </code></pre>
  
  <p>Any ideas, work arounds?</p>
  
  <p>Thanks!</p>