我目前正在使用Firefox SDK创建一个Firefox插件,并希望在面板中显示当前标签的网址。
//index.js
var { ToggleButton } = require('sdk/ui/button/toggle');
var panels = require("sdk/panel");
var tabs = require("sdk/tabs");
var self = require("sdk/self");
var button = ToggleButton({
id: "ESURL",
label: "Shorten this page",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onChange: handleChange
});
var panel = panels.Panel({
contentURL: "./menu.html",
contentScriptFile: "./menu.js",
onHide: handleHide
});
function handleChange(state) {
if (state.checked) {
panel.show({
position: button
});
}
var curtab = tabs.activeTab;
console.log(curtab.url+" is Opened.");//Testing
}
function handleHide() {
button.state('window', {checked: false});
}
//menu.html
<html>
<head>
<link type="text/css" rel="stylesheet" href="menu.css" />
</head>
<body>
<h1>ESURL</h1>
<h3>Shorten this page</h3>
<form>
<input id="link" type="text" value="{LINK}" disabled /><!-- Want the link here -->
<input type="submit" value="Shorten" />
</form>
</body>
</html>
这是我现在所拥有的。 如何获取当前页面网址并在“menu.html #link”中显示?
亲切的问候,
Sven Arends
答案 0 :(得分:0)
也许这会有所帮助:
// Get the url of the current tab
var tabUrl = tabs.activeTab.url;
// Send a message to the panel with the url
panel.port.emit("url", tabUrl);
然后,在 menu.js :
上// When the message arrives
self.port.on("url", function(url){
var link = document.getElementById("link");
link.textContent = url;
}
来源: