簡體   English   中英

消除換行符-JavaScript

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM