javascript - Obtain forwarded URL from a source URL? -


what way obtain end url if given url being forwarded url?

for example, if had shortened url: http://bit.ly/900913, way determine forwards http://www.google.com?

i'm using javascript. i'm unsure if can done somehow using jquery (doubtful since end url isn't returning jsonp content) or if there kind of web service can use.

thanks!

for bit.ly specifically, can use bit.ly api make jsonp call using javascript expand bit.ly url(s) in question.

specifically, you'd use v3/expand call.

pseudo-code:

var bitlyurl = "http://bit.ly/900913"; $.getjson("http://api.bitly.com/v3/expand?shorturl=" + encodeuricomponent(bitlyurl)+"&apikey=...&callback=?", function( bitlydata ){       var endurl  = bitlydata.data.expand[0] //looks end url point }); 

alternately, follow url on own server, , use ajax check it's values.

so, you'd pass url ($.get("/follow?url="+bitlyurl,function(data){var endurl = data.location;});, , make head call url see location points.

here's basics of how you'd in php:

<?php $headers = get_headers($_get["url"],1); echo json_encode($headers); ?> 

just fun, implemented live end-point on app engine check url points. feel free use it! base url followtheredirect.appspot.com, , requires url parameter , callback parameter, , returns location key on resulting object, when successful.

sample code:

$.getjson("http://followtheredirect.appspot.com/?url="+encodeuricomponent('http://bitly.com/hhn7ol')+"&callback=?",function(data){     var location = data.location; }); 

let me know if find bugs :) might bit messy...


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -