javascript - Sending current tab's URL to plugin content -


i'm making add-on firefox using add-on sdk , need somehow active tabs url add-on's content, whenever tab created or switched to.

my main.js looks this:

var { togglebutton } = require('sdk/ui/button/toggle'); var panels = require("sdk/panel"); var self = require("sdk/self");      var button = togglebutton({   id: "my-button",   label: "my button",   icon: {     "16": "./img/icon-16.png",     "32": "./img/icon-32.png",     "64": "./img/icon-64.png"   },   onchange: handlechange });  var panel = panels.panel({   width: 640,   height: 400,   contenturl: self.data.url("index.html"),   onhide: handlehide });  function handlechange(state) {   if (state.checked) {     panel.show({       position: button     });   } }  function handlehide() {   button.state('window', {checked: false}); } 

the index.html that's loaded panel has embedded javascript , that's need send current url to.

i've looked @ documentation here speaks of "content-scripts", i'm unsure of if use, or need use.

so quickest way of doing this? thanks.

you'll need use sdk/tabs module:

var tabs = require("sdk/tabs");  var activetaburl = tabs.activetab.url;  tabs.on("activate", tab => {   activetaburl = tab.url; });  tabs.on("ready", tab => {   if (tab == tabs.activetab) {     activetaburl = tab.url;   } }); 

with activetaburl variable contain url of active tab.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -