Preview in IE command (Windows native version)


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!c:/ruby/bin/rubyw.exe
  2. require 'win32ole'
  3. require 'timeout'
  4.  
  5. filename = ENV['TM_FILEPATH'].chomp.gsub(/\\/, '/').capitalize
  6. url = "file:///" + filename
  7.  
  8. # Methods
  9. def openNewBrowser(url)
  10. begin
  11. Timeout::timeout(5) {
  12. ie = WIN32OLE.new('InternetExplorer.Application')
  13. ie.Navigate("#{url}")
  14. sleep('.2'.to_f) while ie.ReadyState != 4
  15. ie.Visible = 'true'
  16. }
  17. rescue Timeout::Error
  18. puts "Unable connect to #{url} in a reasonable time"
  19. end
  20. end
  21.  
  22. def refreshIfOpen(url)
  23. shell = WIN32OLE.new('Shell.Application')
  24. shell.Windows.each do | window |
  25. if window.LocationUrl == "#{url}"
  26. window.refresh()
  27. return true
  28. end
  29. end
  30. return false
  31. end
  32.  
  33. # Main
  34. unless refreshIfOpen(url)
  35. openNewBrowser(url)
  36. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.