简体   繁体   中英

Encode TextArea for GET request

I need to pass the contents of a textarea as the source attribute of an image tag and capture all input including line breaks etc.

It looks like the only way to do this is to base 64 encode it and then urlEncode the result. (I can then unencode it all server side.)

  1. Is that correct?
  2. Is there a preferred base 64 library for javascript? must be cross browser.

It looks like the only way to do this is to base 64 encode it and then urlEncode the result. (I can then unencode it all server side.)

You only need to base64 encode binary data - which a textarea won't contain.

Just use encodeURIComponent

urlEncode应该足够了(不需要base64,因为您也可以将换行符也表示为%0D%0A ),但是您正在构建的内容听起来很容易受到跨站点脚本攻击的影响。

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