title: Access function from background page in Chrome extension
body: <p>In my background (background.html) page I have the following js:</p>
  
  <pre><code>function capturePage(){
    chrome.tabs.captureVisibleTab(null, function(img){
      var screenshotUrl = img;
      chrome.tabs.create({"url":"history.html"}, function(tab){
        var t = tab;
        var addImage = function(){
          var view = chrome.extension.getViews()[0];
          view.setImageUrl(screenshotUrl);
        }
        chrome.tabs.onUpdated.addListener(addImage);
      });
    });
   }
  
   chrome.browserAction.onClicked.addListener(capturePage);
  </code></pre>
  
  <p>and in history.html I have:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script&gt;
      function setImageUrl(url){
        document.getElementById("target").src = url;
      }
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;img id="target" src="" &gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>However, "view.setImageUrl(screenshotUrl)", in background.html, fails as it says the view has no such function. Just to be clear, I'm trying to access a function within history.html AND pass a parameter to it (screenshotUrl).
  <strong>EDIT:</strong> re Serg's suggestion I replaced the var addImage function in background with the following:</p>
  
  <pre><code>var port = chrome.tabs.connect(tab.id,{name: "history_connect"});
  port.postMessage({mType:"url",url:screenshotUrl});
  </code></pre>
  
  <p>Then added a listener on the history page... worked!</p>