0

I am developing a chrome extension that requires popup.js to access the URL of the currently active tab in chrome. This URL i need to send as paramenter to a php call using ajax. The issue is the url scope. I am unable to access it anywhere other than in the function chrome.tabs.query. I need it to be accessed outside this function so that i can pass it in the ajax call.

popup.js:

$(document).ready(function(){
    var taburl;
  $("#clickme").click(function(event){
     event.preventDefault();  
     chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
        taburl=tabs[0].url;
        document.getElementById('urlh3').innerText=taburl;
        chrome.storage.local.set({'URL': taburl});
    });//query
    var url = "";
    chrome.storage.local.get('URL', function (result) {
    url = result.url;
    //alert(result.url);
    //$("#URL").val(url);
    });
    var b="XYZ";
     $.ajax({
        data:{ url: b},
        type: "POST",
        dataType: "json",
        url: 'http://localhost/hello2.php',
        success: function(results){
            console.log("Result="+results);
        }
     });//ajax
  }); //click
});//ready

The value XYZ gets passed when i tried as sample. But just like i passed var b;, i need to pass taburl, or say do var b = taburl; outside the chrome.tab.query function.

Lucky
  • 16,787
  • 19
  • 117
  • 151
pdb3
  • 1
  • thanks for the edit @Lucky :P. My first question here so kind of noob. – pdb3 Jul 04 '15 at 12:38
  • welcome.;) have you tried this yet http://stackoverflow.com/a/18436323/1793718 – Lucky Jul 04 '15 at 12:42
  • yes i am using the same code as u can see tabs[0].url in my code but the issue is to access it outside the function chrome.tabs.query – pdb3 Jul 04 '15 at 13:17

0 Answers0