Loading jQuery into chrome-extension

前端 未结 2 594
旧时难觅i
旧时难觅i 2020-11-30 10:06

I\'m trying my first step into the magical world of Chrome Extensions. Now i\'ve build up my manifest trying to load jquery.

{
    \"name\": \"Test Extension         


        
相关标签:
2条回答
  • 2020-11-30 10:39
    $.("#test").html("Foo!");
    

    should be

    $("#test").html("Foo!");
    

    The error you are getting is consistent with this part of the code being incorrect.

    0 讨论(0)
  • 2020-11-30 10:43

    Content scripts will never run in the context of an extension. The correct way to load scripts in your browser action popup is by including it in your code. Let your manifest file be:

    {
        "name": "Test Extension",
        "version": "0.1",
        "manifest_version": 2,
        "options_page": "options.html",
        "browser_action": {
            "default_icon": "icon.png",
            "default_popup": "popup.html",
            "default_title": "Click me!"
        }
    }
    

    And popup.html:

    ...
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="popup.js"></script>
    
    0 讨论(0)
提交回复
热议问题