-1

I have gotten the shorten url from the long url which is https://www.jocom.my/. I would like to display the shorten url on current page with javascript when redirected. I have used the window.location.href but it only shows the long url. Can someone help me on this?

code:

  $(document).ready(function() {
    var moo = window.location.href;
    $.ajax({
      url: 'api.jocom.com.my/api/url?url=' + moo,
      type: 'POST',
    })
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
tgogos
  • 23,218
  • 20
  • 96
  • 128
  • Show us your code – Weedoze May 16 '17 at 09:28
  • 1
    Do you want to [change the URL of your page using Javascript](http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page)? Or any of [these](http://stackoverflow.com/search?q=change+url+javascript) – Sandman May 16 '17 at 09:30
  • – user_unavailable May 16 '17 at 09:31
  • If I understand you correctly - you want to get the url of the bit.ly that redirect to your page. If so, you can't using javascript. probably only in the server. – Mosh Feu May 16 '17 at 09:32
  • Hi sandman, i have created the shorten link using bit.ly and it redirecting to the actualy page. I just want to display the shorten url into the page when redirecting has been done. – user_unavailable May 16 '17 at 09:33
  • Hi mosh feu, how can i do that? Im sorry im still new to this. – user_unavailable May 16 '17 at 09:34
  • `display the shorten url on current page with javascript` instead of trying to extract it somehow from the users history, why don't you just use the [bitly API to fetch/create a shortened link](https://dev.bitly.com/links.html#v3_shorten) for your page? – Thomas May 16 '17 at 11:02

1 Answers1

0

I suggest you to host your own URL Shortening service instead. Try https://github.com/azetrix/ShortLink or Try https://github.com/cydrobolt/polr