Generate right links from javascript