Q:

How to pass variable from background_page to tab in Google Chrome extension

I first right click an image.
On clicking the context menu item i am executing a script from my background_page, part of which is - 
function getView(info, tab){
  chrome.tabs.executeScript(null, {code:'var i1hold = document.createElement("img");'});
  chrome.tabs.executeScript(null, {code:'i1hold.setAttribute("id", "i1");'});
  chrome.tabs.executeScript(null, {code:'i1hold.setAttribute("src",' + info.srcUrl + ')'});
  chrome.tabs.executeScript(null, {code:'document.getElementById("image").appendChild(i1hold);'});
}

This line is not working: - 
chrome.tabs.executeScript(null, {code:'i1hold.setAttribute("src",' + info.srcUrl + ')'});

I have also tried: -
chrome.tabs.executeScript(null, {code:'i1hold.setAttribute("src",info.srcUrl)'});

How do i set src attribute to be same as the image which i right clicked to click on context menu item??

A:

Quotes have to be added:
chrome.tabs.executeScript(null,
    {code:'i1hold.setAttribute("src", "' + info.srcUrl + '")'});
//                                    ^                   ^

Also, it's more efficient to concatenate the code in one string, and use chrome.tabs.executeScript once:
function getView(info, tab){
    var code = 'var i1hold = new Image;'
             + 'i1hold.setAttribute("id", "i1");'
             + 'i1hold.setAttribute("src", "' + info.srcUrl + '");'
             + 'document.getElementById("image").appendChild(i1hold);';
    chrome.tabs.executeScript(null, {code: code});
}

