谷歌浏览器扩展名:popup.html javascript vs jquery

Mit*_*tya 0 jquery google-chrome

我正在玩扩展谷歌浏览器,我有一个简单的扩展名运行与以下popup.html文件:

<script type = "text/javascript">
    alert("hi from popup.html");
</script>

<body>
Hello World
</body>
Run Code Online (Sandbox Code Playgroud)

一旦我将带有url的src属性添加到google jquery CDN'alert("来自popup.html");' 不再运行.

我的清单文件如下:

{
  "name": "My First Extension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "background_page": "background.html",
  "browser_action": {
    "default_icon": "icon.png",
"popup": "popup.html"
  },
  "permissions": [
"tabs","http://*/*","https://*/*"
  ]
}
Run Code Online (Sandbox Code Playgroud)

为什么添加jquery源会破坏弹出窗口?

cwh*_*ris 5

您需要将脚本分成两个语句.试试这个:

<script type="text/javascript" src="jQuery.js"></script>
<script type="text/javascript">
    alert("hi from popup.html");
</script>
Run Code Online (Sandbox Code Playgroud)

  • 请记住,现在使用清单版本2不允许使用内联脚本. (5认同)