크롬 확장을 개발할 때 jquery를 추가하는 방법에 대해 여러 게시물을 보았습니다.하지만 대부분은 오래되었고 사용되지 않는 manifest 옵션을 사용합니다 (예 : "background_page"). 이미 "content_scripts"회원을 추가했습니다. 나는 여전히 "잡히지 않은 ReferenceError : $가 정의되지 않았습니다"이됩니다.크롬 확장을 개발할 때 jquery 추가하기
가장 간단한 시나리오를 촬영 - 여기에 jQuery를 추가하는 크롬의 확장 샘플에 구축 - 우리는 같은 것이다 :
매니페스트 :
{ "manifest_version": 2, "name": "myExt", "description": "myExt Desc", "version": "1.0", "browser_action": { "default_icon": "icon.png", "default_popup": "popup.html" }, "content_scripts": [ { "js": [ "jquery.js", "myScript.js" ], "matches": [ "http://*/*", "https://*/*" ] } ] }
myScript.js :
를//var myObj = { // execute: function() { // $("#btn1").click(function() { // alert('I was clicked indeeeed!'); // }); // } //} //document.addEventListener('DOMContentLoaded', function() { // myObj.execute(); //}); $("#btn1").click(function() { alert('iae'); });
popup.html :
내가 같은 디렉토리에있는 모든 파일 (popup.html, icon.png, manifest.json을, myScript.js, jquery.js)가
<html> <head> <title>Getting Started Extension's Popup</title> <style> body { min-width: 357px; overflow-x: hidden; } img { margin: 5px; border: 2px solid black; vertical-align: middle; width: 75px; height: 75px; } </style> <!-- - JavaScript and HTML must be in separate files: see our Content Security - Policy documentation[1] for details and explanation. - - [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html --> <script src="myScript.js"></script> </head> <body> <table> <tr> <td> Hey </td> <td> There </td> </tr> <tr> <td> This is an extension! </td> <td> <input type="button" id="btn1" value="Click Me" /> </td> </tr> </table> </body> </html>
내가 무엇을 놓치고를 정의되어 있지?!?
popup.html의 내용은 무엇입니까? –
popup.html – Veverke