Take the 2-minute tour ×

I am trying to build a Chrome extension that uses injected JS to insert HTML from my server into a Facebook page from my server. Then, I want to be able to call a Javascript function from within the HTML, and have it execute on the Facebook page. The problem is, JS functions that I put in the fhrun.js file don't run on the page when I call them from my HTML file. It may have something to do with the fact that none of the injected JS's functions can be executed from the JS console on Facebook.

Here is the Chrome script I run in the background.js file:

    {file: "fhrun.js", allFrames: false, runAt: "document_start"},
        //JS inserted

This is a simplified fhrun.js (it also contains jquery):

function testFunction(){
console.log("Test function is working.");

$("#facebookDiv").load("https://path.to.my.server/ajax.html"); // this works great btw

This is ajax.html:

<a href="#" onclick="testFunction();">Click Me</a> //link doesn't work

When I click "Click Me," it should call testFunction(); which is inside the JS that has been injected into the page. But it doesn't. It doesn't even throw an error. I also tried putting testFunction(); inside the background.js file, and that didn't work either.

Any suggestions?

share|improve this question
allFrames and runAt should be all_frames and run_at. Your problem description is not sufficiently clear, can you create and share a minimal demo to show your problem (including manifest.json)? Did you know about the differences of the execution context (see this answer)? –  Rob W Nov 15 '12 at 21:39

1 Answer 1

Inline Java Script will not work for JS Injection, use event bindings instead


onload = function (){

document.getElementById("xx").click = fun;


share|improve this answer

Your Answer


