this.window.location.href
is not working in chrome extension
in the html file i tried this function in the script:
function myFunction()
{
var pl = this.window.location.href;
var sWords= localStorage.getItem(pl);
document.write(pl);
}
and it gives me:
chrome-extension://ebeadbfnnghmakkbimckpdmocjffkbjc/popup.html
so what i should do to get the link of the page?
You can get the currently selected tab via chrome.tabs.query
method. You need to pass two options:
currentWindow : true
active : true
It will return an array of tabs that match the criteria. You can get the URL from there. Like this:
chrome.tabs.query(
{
currentWindow: true, // currently focused window
active: true // selected tab
},
function (foundTabs) {
if (foundTabs.length > 0) {
var url = foundTabs[0].url; // <--- this is what you are looking for
} else {
// there's no window or no selected tab
}
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With