/ Published in: Ruby
The escape_javascript funtion is taken from Rails (http://rails.rubyonrails.com/classes/ActionView/Helpers/JavaScriptHelper.html#M000633). Most of the work on this was done by pnomolos and n00ge on the E Text Editor forums.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env ruby require 'socket' def escape_javascript(javascript) (javascript || '').gsub('\\','\0\0').gsub(/ |\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" } end refresh = escape_javascript("javascript:void(function(){var i,a,s;a=document.getElementsByTagName('link');for(i=0;i<a.length;i++){s=a[i]; if(!s.href){continue;}var h=s.href.replace(/(&|%5C?)forceReload=\d+/,'');s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf())}})();") jssh_socket = TCPSocket::new("localhost", 9997); jssh_socket.puts("getWindows()[0].getBrowser().loadURI('#{refresh}')") jssh_socket.close
URL: http://www.e-texteditor.com/forum/viewtopic.php?p=6358