【发布时间】:2017-02-19 14:31:31
【问题描述】:
我想要一个 google chrome 扩展程序,它可以给用户一个单词并在亚马逊网站上搜索它,并在单个 HTML 页面上向用户显示搜索结果。
我尝试使用 JavaScript 和 DOM,这是我的代码:
manifest.json:
{
"manifest_version": 2,
"name": "Amazon Search",
"description": "This extension to sarch from Amazon.com",
"version": "0.1",
"browser_action": {
"default_icon": "amazon.png",
"default_popup": "form.html"
},
"background":
{
"scripts": ["search.js"]
},
"permissions": [
"activeTab",
"tabs",
"https://ajax.googleapis.com/",
"https://amazon.com/"
]
}
form.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Form</title>
<script src="search.js"></script>
</head>
<body>
<form>
<label>Search : </label><input type="text" id="search" />
<button id="gotoamazon" >Search Amazon</button>
</form>
</body>
</html>
search.js:
var searchItem = document.getElementById('search').value;
console.log(searchItem);
function amazon(){
window.open('https://amazon.com','_blank');
document.getElementById('twotabsearchtextbox').value = searchItem;
document.getElementById('nav-search-submit-text').click();
var results = document.getElementById('resultsCol').value;
};
document.getElementById('gotoamazon').addEventListener('click', amazon);
我有一些麻烦,如何在另一个页面上显示搜索结果(结果变量)?
【问题讨论】:
标签: javascript dom google-chrome-extension amazon