Content Script cross domain or message passing
<p>I am writing a javascript extention that modifies a website. The extention adds a button to the website, and when clicked it modifies the page content. My script has to send cross domain xmlhttprequests to websiteB, and gets permissions upon installation to do so. </p>

<p>My problem is that the code that runs in the content scope of the website that I am modifying does not have permission to do cross domain requests, because it is within a content scope of the webpage. Nor can I easily pass variables between my main extention code and the code that runs upon the button click on the page.</p>

<p>These are the relevant parts of my code:</p>

<pre><code>    // ==UserScript==
    // @include        http://www.WebsiteB.com/*
    // @match          http://www.WebsiteB.com/*
    // ==/UserScript==

    var a = 1;

    button.innerHTML = '&lt;a href="javascript:void(0)" onclick="myFunc();"&gt;clickMe&lt;/a&gt;';
    menu.appendChild(button);

    contentEval(function() {
        myFunc = function() {
            //a is undefined

            //this part does not have cross domain request permission   
        };
    }
</code></pre>

<p>I use contentEval taken from <a href="http://wiki.greasespot.net/Content_Script_Injection" rel="nofollow">http://wiki.greasespot.net/Content_Script_Injection</a> to get the relevant code to be able to interact with the page my script is running on. Without it, I would not be able to call myFunc from a button on the website.
variables can not be transferred from the main code area to myFunc() by passing them directly using myFunc(a) either. myFunc(1) works, but does not suit my needs.</p>

<p>It's possible that I am going about things the wrong way. If so, please enlighten me.</p>

<p>Is there a way to have cross domain permissions from the code that interacts with the web page?
If not, what should I use to do message passing from the main code area to the content script of the page?</p>
