Is it possible to call function on a page?
For example I have a page called help.html and that page has a function called help(id).
Can I call this function and pass the id to it?
Thanks in advance
Is it possible to call function on a page?
For example I have a page called help.html and that page has a function called help(id).
Can I call this function and pass the id to it?
Thanks in advance
如果页面已打开并加载,并且您有对其window
对象的引用,则可以。确保这两件事都正确的一种方法是让帮助窗口上的代码在准备好后调用后台页面上的函数,并传递对自身的引用。因此,在您的帮助窗口中,您可以使用以下内容:
chrome.extension.getBackgroundPage().helpWindowLoaded(window);
在您的背景页面上:
function helpWindowLoaded(helpWindow) {
helpWindow.help(id);
}
我不确定我是否理解您的问题,但最好创建一个单独的 js 文件。这是一个示例(我使用 jQuery):
popup.html:
<html>
<head>
<script src="jquery-2.0.3.js"></script>
<script src="popup.js"></script>
</head>
<body>
<input id="amount" type="text" />
<input id="addAmount" type="submit" value="Add" />
</body>
</html>
popup.js:
$(function() {
$('#addAmount').click(function() {
alert('hi');
});
});