[英]Eradicate line breaks - javascript
我下面有两个PHP变量来构建一个字符串,完成后将成为发布到Twitter的URL:
$encUrl = 'http://example.com/wish/'.str_replace(' ','-',$id[item_title]).'/'.$id[wish_id];
$encTitle = urlencode($id[item_title]);
$tweetTo = "https://twitter.com/share?url=$encUrl&text=$encTitle&via=myTwitter";
然后在javascript中,我正在尝试:
window.open("<?=$tweetTo?>","","width=600,height=450");
当页面呈现时,尽管它通过添加换行符而中断,例如
window.open(https://twitter.com/share?url=http://example.com/wish/Antique-earrings
/11786&text=Antique+earrings%0D%0A&via=myTwitter,"","width=600,height=450");
错误是
unterminated string literal
window.open("https://twitter.com/share?url=http://example.com/wish/Antiq
有没有解决的办法?
@达伦 您还需要编码$encUrl
。 浏览器或任何其他脚本语言将无法理解URL中的URL。
https://twitter.com/share?url=http://example.com/wish/Antique-earrings
必须对url=
之后的部分(即http://example.com/wish/Antique-earrings )进行编码。
希望能有所帮助。 如有其他问题,请通知我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.