It cannot access popup.js file after creating chrome extension

manifest.json

{
  "name": "Summer",
  "version": "1.0",
  "manifest_version": 2,
  "description": "This is an addition extension",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  }
}

popup.html

<!doctype html>
<html>
  <head>
    <title>Getting Started Extension Popup</title>

    <!-- JavaScript and HTML must be in separate files for security. -->
    <script src="popup.js"></script>
  </head>
  <body>
        <form name="form">
            <div id="sayi1">Sayı 1 :    <input type = "text" name="deger1"></div> 
            <div id="sayi2">Sayı 2 :    <input type = "text" name="deger2"></div> 
            <div id="sonuc">Sonuç :     <input type = "text" name="cevap"></div>
            <div id="button"><input type="button" value="Hesapla" onclick="hesaplama()" /></div>
        </form>
  </body>
</html>

popup.js

function hesaplama()
{
var sayi1 = window.document.form.deger1.value;
var sayi2 = window.document.form.deger2.value;
var toplam = parseFloat(sayi1) + parseFloat(sayi2) ;
window.document.form.cevap.value = toplam; 
}

When I download this extension, I can see it normally. But when I filled in the text field deger1 and deger2 and pressed the button, the function does not work, in the text field sonuc (result textbox) is null. How can i fix this? I am new to creating chrome extensions. Thank you for your help.

+3
source share
1 answer

manifest_version : 2 , , , , ....
http://code.google.com/chrome/extensions/manifestVersion.html
Refused to execute inline event handler because of Content-Security-Policy - onclick html (<input type="button" value="Hesapla" onclick="hesaplama()" />). 2 , js-, html.
....
popup.html

<!doctype html>
<html>
  <head>
    <title>Getting Started Extension Popup</title>

    <!-- JavaScript and HTML must be in separate files for security. -->
    <script src="popup.js"></script>
  </head>
  <body>
        <form name="form">
            <div id="sayi1">Sayı 1 :    <input type = "text" name="deger1"></div> 
            <div id="sayi2">Sayı 2 :    <input type = "text" name="deger2"></div> 
            <div id="sonuc">Sonuç :     <input type = "text" name="cevap"></div>
            <div id="button"><input type="button" value="Hesapla" /></div>
        </form>
  </body>
</html>

popup.js

function hesaplama()
{
var sayı1 = window.document.form.deger1.value;
var sayı2 = window.document.form.deger2.value;
var toplam = (parseFloat(sayı1) + parseFloat(sayı2)) ;
window.document.form.cevap.value = toplam;
}
window.onload = function(){
    document.querySelector('input[value="Hesapla"]').onclick=hesaplama;
}
+6

All Articles