我正在尝试开发Chrome扩展程序,但是一旦我将数据传递给popup.html,就会显示找不到页面错误。
下面是popup.js页面的代码: -
// When the popup HTML has loaded
window.addEventListener('DOMContentLoaded', function(evt) {
// Get the event page
chrome.runtime.getBackgroundPage(function(eventPage) {
// Call the getPageInfo function in the event page, passing in
// our onPageDetailsReceived function as the callback. This injects
// content.js into the current tab's HTML
eventPage.getPageDetails(onPageDetailsReceived);
});
});
function onPageDetailsReceived(pageDetails) {
document.getElementById('title').value = 'abcd';
document.getElementById('location').value = 'abcd';
document.getElementById('email').value = 'abcd';
document.getElementById('skill').value = 'abcd';
document.getElementById('contact').value = 'abcd';
}
下面是popup.html页面的代码,我在其中添加了要传递详细信息的表单 : -
<!DOCTYPE html>
<html>
<head>
<style>
body {
min-width: 420px;
overflow-x: hidden;
font-family: Arial, sans-serif;
font-size: 12px;
}
input, textarea {
width: 420px;
}
input#save {
font-weight: bold; width: auto;
}
</style>
<script src="popup.js"></script>
</head>
<body>
<form id="addbookmark">
<p><label for="title">Title</label><br />
<input type="text" id="title" name="title" size="50" value="" /></p>
<p><label for="location">Location</label><br />
<input type="text" id="location" name="location" size="50" value="" /></p>
<p><label for="email">Email</label><br />
<input type="email" id="email" name="title" size="50" value="" /></p>
<p><label for="contact">Contact</label><br />
<input type="text" id="contact" name="contact" size="50" value="" /></p>
<p>
<p><label for="skill">Skills</label><br />
<input type="skill" id="skill" name="skill" size="50" value="" /></p>
<p>
<input id="refer" type="submit" value="Refer Your Friend" />
<span id="status-display"></span>
</p>
</form>
</body>
</html>
manifest.json: -
{
"manifest_version": 2,
"name": "My Chrome Extension",
"description": "Chrome Extension",
"version": "0.2",
"background": {
"scripts": ["event.js"],
"persistent": false
},
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
]
}