简体   繁体   中英

Javascript Function window.location.href

I am trying to change the line

var url = window.location.href;

to point to an API which can get a shorted Link of the actual Page.

My idea was to set it by this way

var url = 'http://bit.ly/api.php?url=' . urlencode('http://' . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI']));

and send this to Twitter

var twit = 'http://twitter.com/home?status='+title+'%20'+url;

Get the report that i have a Syntax Error but dont know which one.

  • The JavaScript concatenation operator is + not .
  • urlencode is a PHP function, you want encodeURIComponent
  • $_SERVER is a PHP superglobal, you still want location.href

Such:

var url = 'http://bit.ly/api.php?url=' + encodeURIComponent(location.href);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM