我使用下面的代码和文件片段构建了我的第一个Chrome扩展程序。如何在Chrome扩展中使用jQuery打开链接?
的manifest.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);
});
});
正如你看到的,我应该做的就是打开谷歌搜索结果页面在一个新的窗口与用户搜索输入。但不幸的是,它不适合我,所以有什么不对,我怎么能相应这是什么?
对不起丢失选择器'#':-) – 2013-05-13 16:11:41
你在元素被解析之前引用元素。将代码包装在'$()。ready'处理程序中,或者在'