Author Topic: fix browser_preview_ie.vbs  (Read 1507 times)

Offline coolcheng168

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
fix browser_preview_ie.vbs
« on: October 29, 2012, 05:47:34 am »
Code: Visual Basic
  1. Set objArguments = Wscript.Arguments     'Create the Arguments object
  2.  
  3. If objArguments.Count > 0 Then
  4.                 file_path = objArguments.Item(0)                'Get the argument that we gave when we run the script
  5.                 root_place = Instr(1, file_path, "wwwroot", 1)          'Find the place of wwwroot string inside the path
  6.  
  7.                 If not root_place = 0 Then
  8.                         separate_from = root_place+8            'If we find wwwroot string, extend selection with 8 chars to the next \ that we will separate the path from
  9.                 Else
  10.                         dot_place = Instr(1, file_path, ":", 1)          'If we can't find wwwroot then seacrh for : char
  11.                         separate_from = dot_place+2      'Then extend selection with 2 chars to the next \ that we will separate the path from
  12.                 End If
  13.  
  14.                 If not separate_from = 0 Then
  15.                         file_path = Mid(file_path, separate_from)        'Separate path from the point that we got
  16.                         file_path = Replace(file_path, "\", "/", 1, -1, 1)              'Replace \ chars with / chars since we will open the path in the browser
  17.                         file_path = Replace(file_path, " ", "%20", 1, -1, 1)            'Replace space chars with %20 chars since we will open the path in the browser
  18.                         page = "http://localhost/" & file_path          'Add server address to the file path to run our server side script
  19.                 End If
  20.  
  21.                 'Create other necessary objects.
  22.                 Set objShell = WScript.CreateObject("WScript.Shell")
  23.                 Set objShellApplication = WScript.CreateObject("Shell.Application")
  24.                 Set objShellWindows = objShellApplication.Windows
  25.                 Set objIE = WScript.CreateObject("InternetExplorer.Application")
  26.  
  27.                 'Find the old window if it is opened already.
  28.                 For n = 0 to objShellWindows.Count - 1          'Search among the open IE windows
  29.                         Set IE = objShellWindows.Item(n)
  30.                         If Err Then  'look here
  31.                           Err.Clear
  32.                         End If
  33.                         URL = IE.LocationURL     'Get the URL of IE window that we currently work on
  34.                         If URL = page Then              'If the URL of the window is equal to our file path. Then we found the old window that we search for
  35.                                 IE.Quit          'Close the old IE window since we will open a new one
  36.                         End If
  37.                 Next
  38.  
  39.                 objIE.Navigate page      'Open a new IE window and navigate to our page.
  40.                 IEName = objIE.Name      'Get the name of the window that we just opened
  41.                 objShell.AppActivate IEName      'Activate the window to focus and bring it to front.
  42. Else
  43.          MsgBox "No parameter given."
  44. End If
« Last Edit: October 29, 2012, 12:25:20 pm by alex »

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2181
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: fix browser_preview_ie.vbs
« Reply #1 on: October 29, 2012, 12:29:42 pm »
What about migrating this to HippoEDIT script available with 1.50?
You can still use VBS - it is supported, but get additional functionality available from HE engine. For example to get selection, create a command or add menu entry/toolbar button.
HippoEDIT also emulates some of the WScript methods, so you should not do too much changes.