开发者

refresh firefox from .bat file/ command

开发者 https://www.devze.com 2023-01-24 11:02 出处:网络
I am attempting to ref开发者_如何学运维resh Firefox whenever a bat file is called. I Dont want an extension. I need to know if there is a command that can be used from within a .bat file to reload the

I am attempting to ref开发者_如何学运维resh Firefox whenever a bat file is called. I Dont want an extension. I need to know if there is a command that can be used from within a .bat file to reload the current browser or tab.

I know you can use start firefox as a command but this simply opens a new firefox instance. I need to refresh the current instance.


I was just messing around and came up with this half-working solution that might help a little. Create a file called something like refresh.vbs and paste this in:

Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.AppActivate("Google Chrome")
WScript.Sleep 500
WshShell.SendKeys "{TAB}" 
WScript.Sleep 100
WshShell.SendKeys "{F5}" 

I could only test it with Chrome. The script activates Chrome, sends a tab, and then sends F5 to refresh. It works when I have Chrome up showing one web page, but not when there are multiple web tabs open (because AppActivate activates the Window, but does not give focus to anything).

Maybe it works better with Firefox. There's probably some way to enumerate the tabs in a browser and activate it in vbs, but I don't know it.

If you spawn the browser within the vbs (see WshShell.Run, and the example in the SendKeys documentation), you can get the process number and send messages directly to that Window instead of relying on the app title.

You can invoke the .vbs from within a batch file if you need to:

@echo off
refresh.vbs


On Error Resume Next

Set objExplorer = CreateObject("InternetExplorer.Application")

objExplorer.Navigate "http://www.microsoft.com/technet/scriptcenter"   
objExplorer.Visible = 1

Wscript.Sleep 5000

Set objDoc = objExplorer.Document

Do While True

Wscript.Sleep 30000
objDoc.Location.Reload(True)
If Err <> 0 Then
    Wscript.Quit
End If

Loop
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号