0

So I made a extension for a website where your money is refreshed dynamically and I want the value of that div inside of my extension, It doesn't seem to refresh or work at all. I'm posting releated stuff, if you want to know anything else you request and I will provide information. I'm trying to learn jQuery so I'm not the best at the language (yet).

popup.js

  var cash = $("#v4").html();
  $('.cash').append(cash);

my extension html page

<script type="text/javascript">
    $(".cash").append($("#v4").html());
</script>

<div class="cash"></div>

My error

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

Konrad Dzwinel
  • 36,825
  • 12
  • 98
  • 105
Tweath
  • 124
  • 6
  • 24
  • you need to put your script in separate file, see : http://stackoverflow.com/a/16153913/3546305 – amiceli Jan 05 '15 at 20:53

2 Answers2

1

You have to wait for the DOM to load. Right now you are executing the code before the $('.cash') is even on the page. Try this:

$(document).ready( function(){
  $(".cash").append($("#v4").html());
});
britter
  • 137
  • 6
  • Still the same error, and the `.cash` isn't updating. @britter – Tweath Jan 05 '15 at 21:15
  • Your error implies that Chrome browser will not execute the update $(.cash) statement found on your html page because it is "inlined". Maybe try relocating the inline JavaScript to a separate file, but you still must wait for the DOM to load. Throw in an if statement like this if ($('.cash').length == 0)) { alert('not found'); } – britter Jan 05 '15 at 21:20
  • I didn't quite understand, english isn't my native language. @britter – Tweath Jan 05 '15 at 21:26
0

Try

var cash = "<div id='V4'></div>";
$('.cash').append(cash);