×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Ruby
Posted by: petecocoon
Added: Jan 4, 2013 10:43 AM
Modified: Jan 4, 2013 10:44 AM
Views: 15
in your views (haml or erb)
= safe_js_print 'this.is.a.big.test@test.com'
become
<script type="text/javascript">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%74%68%69%73%2e%69%73%2e%61%2e%62%69%67%2e%74%65%73%74%40%74%65%73%74%2e%63%6f%6d%27%29%3b'))</script>
  1. #put it in your application helper  
  2. def safe_js_print html
  3.     string = ''
  4.    "document.write('#{html}');".each_byte do |c|
  5.       string << sprintf("%%%x", c)
  6.     end
  7.     "<script type=\"#{Mime::JS}\">eval(decodeURIComponent('#{string}'))</script>".html_safe
  8.   end