homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

JSONP and passing a URL value as a parameter - Chrome Extensions
How to pass a URL value as part of the JSON parameter - cross-domain script

5+ Year Member

Msg#: 4403389 posted 1:59 am on Jan 4, 2012 (gmt 0)


Ok, this is my final tango with this. Below I've listed the code. I'm able to get the value of the url and display it on screen for the current (active tab) in Google Chrome. Now all I have to do is pass that value as a parameter in the URL via JSON. My processing file resides on a our remote server - in php. Everything I've done with respect to this has worked to perfection. However, any attempts to pass the current url or any url as one of the parameters - e.g. ?format=json&url=http://something.com&callback=? - results in nothing. I'm not sure if what I'm doing is wrong or if it is even possible. The important thing to note is that all we are looking to do is pass the url to a remote server for storage, processing etc and send back results. I have everything working but I just can't seem to get the url to pass as a parameter.

    <title>API JSON Test</title>
    <script type="text/javascript"  
        window.addEventListener("load", windowLoaded, false);
        function windowLoaded() {
          chrome.tabs.getSelected(null, function(tab) {
            document.getElementById('currentLink').innerHTML = tab.url;

    <script type="text/javascript">


   var timeService =

    $.getJSON(timeService, function(data) {
        <div id="showdata"></div>


Again, all the JSON works fine when I'm testing other code. Even if I put in a NON-URL value as a parameter for url=..... it throws the appropriate error. However, it will not accept a URL for some reason.

Any feedback will be greatly appreciated.

Thanks, Ethan-Anthony



5+ Year Member

Msg#: 4403389 posted 7:34 am on Jan 4, 2012 (gmt 0)

querystring variables' values which may contain special characters must be escaped, so use encodeURIComponent(uri) [w3schools.com] like so:
var timeService =
"http://api.ulore.com/api2.php?key=abce&url="+ encodeURIComponent(tab.url) +"&format=json&callback=?";

and see if that works, good luck!


5+ Year Member

Msg#: 4403389 posted 1:31 pm on Jan 19, 2012 (gmt 0)

Thank u Astupidname,

It work! Much appreciated.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved