ext/win32ole/sample/ienavi.rb


DEFINITIONS

This source file includes following functions.


   1  require 'win32ole'
   2  
   3  $urls = []
   4  
   5  def navigate(url)
   6    $urls << url
   7  end
   8  
   9  def stop_msg_loop
  10    puts "Now Stop IE..."
  11    $LOOP = FALSE;
  12  end
  13  
  14  def default_handler(event, *args)
  15    case event
  16    when "BeforeNavigate"
  17      puts "Now Navigate #{args[0]}..."
  18    end
  19  end
  20  
  21  ie = WIN32OLE.new('InternetExplorer.Application')
  22  ie.visible = TRUE
  23  ie.gohome
  24  
  25  ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents')
  26  
  27  ev.on_event {|*args| default_handler(*args)}
  28  ev.on_event("NavigateComplete") {|url| navigate(url)}
  29  ev.on_event("Quit") {|*args| stop_msg_loop} 
  30  
  31  $LOOP = TRUE
  32  while ($LOOP)
  33    WIN32OLE_EVENT.message_loop
  34  end
  35  
  36  puts "You Navigated the URLs ..."
  37  $urls.each_with_index do |url, i|
  38    puts "(#{i+1}) #{url}"
  39  end
  40