K
K
Kirill Morozov2017-03-01 14:54:09
JavaScript
Kirill Morozov, 2017-03-01 14:54:09

How to get the URL of the active tab using JavaScript on a button click in a Chrome extension?

If you specify "window.location.href" - it gives the address of the extension, not the open browser tab

document.addEventListener('DOMContentLoaded', function() {
    var checkPageButton = document.getElementById('life');
    checkPageButton.addEventListener('click', function() { 
        chrome.tabs.getSelected(null, function(tab) {
        	
       
        var url=   ?????

        	alert(url);
    
        });
    }, false);
}, false);

Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wscms, 2017-03-01
@wscms

What about document.location.href ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question