Browser Preview Scripts for Server Side Languages

Started by Theno, April 19, 2010, 05:28:29 PM

Previous topic - Next topic

Theno

Hi friends,

I wrote two scripts for browser preview of the page you currently work on, in IE and Firefox, using installed server on your PC. These scripts can be used by any web programmer who uses server side languages like ASP, ASP.NET, PHP, JSP etc. just with small changes.

Scripts are written for ASP language, other programmers can use it with changing the path string as they wish. IE browser preview opens the ie page automatically using the server string that you added. And if you run the script again while the old ie page is still open, it finds and closes the old one and opens a new one. I couldn't do it for firefox in same way because of the limitations of the windows scripting engine. But however it can be done with small programs like AHK etc. But I didn't implement something like this yet, since I want to keep the codes simple.

IE Browser Preview Script (for ASP)
Code (vb) Select

Set objArguments = Wscript.Arguments 'Create the Arguments object

If objArguments.Count > 0 Then
file_path = objArguments.Item(0) 'Get the argument that we gave when we run the script
root_place = Instr(1, file_path, "wwwroot", 1) 'Find the place of wwwroot string inside the path

If not root_place = 0 Then
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
Else
dot_place = Instr(1, file_path, ":", 1) 'If we can't find wwwroot then seacrh for : char
separate_from = dot_place+2 'Then extend selection with 2 chars to the next \ that we will separate the path from
End If

If not separate_from = 0 Then
file_path = Mid(file_path, separate_from) 'Separate path from the point that we got
file_path = Replace(file_path, "\", "/", 1, -1, 1) 'Replace \ chars with / chars since we will open the path in the browser
file_path = Replace(file_path, " ", "%20", 1, -1, 1) 'Replace space chars with %20 chars since we will open the path in the browser
page = "http://localhost/" & file_path 'Add server address to the file path to run our server side script
End If

'Create other necessary objects.
Set objShell = WScript.CreateObject("WScript.Shell")
Set objShellApplication = WScript.CreateObject("Shell.Application")
Set objShellWindows = objShellApplication.Windows
Set objIE = WScript.CreateObject("InternetExplorer.Application")

'Find the old window if it is opened already.
For n = 0 to objShellWindows.Count - 1 'Search among the open IE windows
Set IE = objShellWindows.Item(n)
URL = IE.LocationURL 'Get the URL of IE window that we currently work on
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
IE.Quit 'Close the old IE window since we will open a new one
End If
Next

objIE.Navigate page 'Open a new IE window and navigate to our page.
IEName = objIE.Name 'Get the name of the window that we just opened
objShell.AppActivate IEName 'Activate the window to focus and bring it to front.
Else
MsgBox "No parameter given."
End If



Firefox Browser Preview (for ASP)

Code (vb) Select
Set WshArguments = Wscript.Arguments 'Create the Arguments object

If WshArguments.Count > 0 Then
file_path = WshArguments.Item(0) 'Get the argument that we gave when we run the script
root_place = Instr(1, file_path, "wwwroot", 1) 'Find the place of wwwroot string inside the path

If not root_place = 0 Then
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
Else
dot_place = Instr(1, file_path, ":", 1) 'If we can't find wwwroot then seacrh for : char
separate_from = dot_place+2 'Then extend selection with 2 chars to the next \ that we will separate the path from
End If

If not separate_from = 0 Then
file_path = Mid(file_path, separate_from) 'Separate path from the point that we got
file_path = Replace(file_path, "\", "/", 1, -1, 1) 'Replace \ chars with / chars since we will open the path in the browser
file_path = Replace(file_path, " ", "%20", 1, -1, 1) 'Replace space chars with %20 chars since we will open the path in the browser
page = " http://localhost/" & file_path 'Add server address to the file path to run our server side script
End If

Set WshShell = WScript.CreateObject("WScript.Shell") 'Create the Shell object
firefox_path = """C:\Program Files (x86)\Firefox\firefox.exe""" 'Define the full path of firefox.exe on the PC
Return = WshShell.Run (firefox_path & page,1) 'Run firefox with page you created and gave as a argument.
Else
MsgBox "No parameter given."
End If


You can find the explanations of the codes as comments near them also you can see the codes in the screenshots too. They are created and copied inside the main folder of HE but you can store it anywhere you want but this time you will need the give the full path of the script while creating the tool.

You can see the tool details that are needed to be created as screenshots too.

I hope it can be useful for other web programmers.

Special thanks to Alex and Stefan for their interest and helps. Also if you are interested in extending code with AHK please refer to Stefan's message in this topic.

http://forum.hippoedit.com/index.php/topic,747.msg3286.html#new

Thanks...

alex

Hi Theno,

thanks a lot for your support! ;)
Useful post and good how-to. I am doing HE site in PHP, so I can try to use your scripts until "normal" support will be added into HE.

Checking your images, I got the idea, that it Will be good to add Import/Export possibilities for tools/help items in "Manage" dialogs that it will be easier to share them. I will note it as todo for 1.50.

Best regards,
Alex.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Theno

#2
Hi Alex,

Quotethanks a lot for your support!
Nop, I am glad you found them useful. ;)

Quote
Checking your images, I got the idea, that it Will be good to add Import/Export possibilities for tools/help items in "Manage" dialogs that it will be easier to share them. I will note it as todo for 1.50.

Yes this is a very good idea it can very time saving.

P.S : I added the scripts as attachment to the first post.

Thanks...