0

I am making a bookmarklet for my url shortener. What it does is it shortens the current url of a page when you click on the bookmarklet, so you don't have to go to a site to shorten a url, but what I need is for the bookmarklet to return a pop-up window with the shortened url listed below.

What I've done so far is this:

javascript:u=encodeURIComponent(location.href);s='http://n1x.co.uk/create.php?url='+u;window.open(s,'shortened','location=no,width=400,height=300');

If you have bookmarked this, you will notice when you click on it, it does shorten the url of the current page, but it also shows the url shortener webpage, and what I only need is plain text and a link to copy it.

Please help!

Edit: Sorry I'm that bad at php, but how can I make a parameter "responseType"? Thanks

Nick
  • 352
  • 2
  • 5
  • 20
  • You were closer to that with [your JSONP approach](http://stackoverflow.com/questions/10585645/how-to-make-an-instant-shorten-link-for-a-url-shortener), although `prompt()` should be avoided - for one thing, IE doesn't like it very much. If might be better if you use this current approach, and add a (for example) `&bookmarklet=1` parameter to the URL and just generate a small page designed to run in the 400x300 window when this parameter is present. – DaveRandom May 14 '12 at 15:42

1 Answers1

1

What is shown in the popup is what is returned by http://n1x.co.uk/create.php. You will have to modify the php to return only the shortened url in plain text. If the php is being used by the shortener site also, what you can do is pass a parameter to create.php that tells it whether to return the whole page like it does now or to return only the plain text url. For example a parameter called 'responseType'. You can modify the create.php to say that when responseType = 'plainurl', return simply the shortened url and not the whole page.

javascript:u=encodeURIComponent(location.href);s='http://n1x.co.uk/create.php?url='+u + '&responseType=plainurl';window.open(s,'shortened','location=no,width=400,height=300');
septerr
  • 6,445
  • 9
  • 50
  • 73
  • Like shown in the code snippet above add responseType=plainurl to the url. In your php file you can get the value of responseType parameter by doing something like: $_GET["responseType"] should return a value of plainurl. Then you can have if else logic that says if $_GET["responseType"]=='plainurl' return the shortened url only else return what it returns now. – septerr May 14 '12 at 16:22