Consider this code:
function SwapColumns() {
chrome.tabs.executeScript(null,
{code:"SwapNameAndSurname();"});
}
The code above is in popup.html, the method SwapNameAndSurname() is in a content script named js.js that contains nothing but a library full of functions. When I call the SwapColumns function from popup.html, the SwapNameAndSurname() function in js.js is called changing something in the DOM of the original page via the power of content scripts.
However my problem is here. I have prepared an object named employee in popup.html that I need to send to the SwapNameAndSurname() function as a parameter:
var employee = {'Name' : 'John', 'Surname' : 'Doe', 'Qualifications' : [{'Title':'MCAD', 'Date':'Jan 2008'},{'Title':'MCSA', 'Date':'Feb 2008'}]};
function SwapColumns() {
chrome.tabs.executeScript(null,
{code:"SwapNameAndSurname(**???employee???**);"});
}
How can I do that? Since in chrome.tabs.executeScript you have to write code directly into a string, you cannot really send parameters. I've read Chrome's tabs.executeScript - passing parameters and using libraries? but still can't figure out what's happening.