window.open 在 chrome 扩展弹出窗口中不起作用

window.open not working in chrome extension popup

我想在弹出页面上创建一个按钮,点击后重定向到 google 搜索页面 所以我用了 window.open 这是 html

<li> 
    <input type="image" src="http://www.google.com/s2/favicons?domain=www.google.com" onClick="google()">
</li>

和 javascript

function google(){ 
    window.open("http://www.google.com/search?q="+document.search.query.value);
}

当我在 chrome window 中预览代码时效果很好,但在扩展弹出页面中按钮没有任何作用,为什么?

Chrome 扩展不能使用内联代码。相反,获取 Javascript 中的元素。参见 https://developer.chrome.com/extensions/contentSecurityPolicy

请检查这个 onClick within Chrome Extension not working

Chrome 应用程序 Inline JavaScript will not be executed

我以前也遇到过这个问题,不过我用的是Jquery,目前还好。