以下のコードとファイル スニペットを使用して、最初の 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);
});
});
ご覧のとおり、私がすべきことは、Google 検索結果ページを新しいウィンドウで開いてユーザー検索入力を行うことですが、残念ながら私にはうまくいきません。