Michael Baldry
Michael Baldry

Reputation: 2028

Chrome Extensions background page window variable

I'm trying to share objects between my javascripts.. In my background.html I have:

<html>
  <head>
    <script type="text/javascrpt">
      window.Something = {};
    </script>
  </head>

  <body>
    <script type="text/javascript" src="../js/file1.js"></script>
    <script type="text/javascript" src="../js/file2.js"></script>
  </body>
</html>

and in file1.js I have:

alert("1: " + window.Something);

and in file2.js I have:

alert("2: " + window.Something);

when I reload my extension I just get 2 alerts:

1: undefined 2: undefined

Whats the deal?! Thanks everyone

Upvotes: 0

Views: 756

Answers (1)

Sudarshan
Sudarshan

Reputation: 18534

Remove script written in background.html

Use the following code instead

<html>
  <head>
    <script src="js/file3.js"></script>
 <script  src="js/file1.js"></script>
    <script  src="js/file2.js"></script>
  </head>
  <body>
  </body>
</html>

I assume you have a folder called js

file3.js

window.Something = {};

For more information refer the following link

http://developer.chrome.com/extensions/contentSecurityPolicy.html#JSExecution

Upvotes: 1

Related Questions