我使用下面的代码和文件片段构建了我的第一个 Chrome 扩展。
清单.json
{
"name": "Test",
"version": "0.1",
"manifest_version": 2,
"description": "First try",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
popup.html
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="jquery.js"></script>
<script src="popup.js"></script>
</script>
</head>
<body>
<input id="input1">
<input id="input2" type="submit">
</body>
</html>
popup.js
$(document).ready(function() {
$('#input2').click(function(){
alert('test');
var whatISearch = $('#input1').val();
//chrome.tabs.create({'url': "https://www.google.com/search?s=" + whatISearch});
window.open("https://www.google.com/search?s=" + whatISearch);
});
});
如您所见,我应该做的是在带有用户搜索输入的新窗口中打开谷歌搜索结果页面。但不幸的是它对我不起作用,所以有什么问题吗?我该如何纠正这个问题?