How to reload/refresh a web page without leaving m

2020-02-16 06:59发布

Building Websites

When I build websites I use 2 monitors. I have my development IDE on the main monitor and the web page open on the secondary screen.

I get annoyed that everytime I need to refresh the web page I have to go to my mouse, move over to the other screen and click refresh.

I would like to have a shortcut key mapped to reloading the web page whenever I need. In a similar way to how Winamp maps keys to common functions like play/pause etc.

My current research:

Firefox via Command Line

I have discovered that an existing FireFox process can be controled from the command line, however the best it can do is create a new window with a specific URL.

firefox -remote "openURL(www.mozilla.org, new-tab)"

The documentation is here: https://developer.mozilla.org/en/Command_Line_Options

Reload Every

There is also a firefox extension that will refresh the web page periodically. However this results in a constant flickering of the page and will also be wasteful with resources.

https://addons.mozilla.org/en-US/firefox/addon/115/

However, what I really need is either....

  • A customisable global hotkey for Firefox/Chrome to reload current selected tab
  • A browser extension that could be fired from a Global Hotkey
  • A command to reload the current selected tab from the Command Line that I could then map to a hotkey (is it possible to add extra remote command with an extentsion?)

Does anyone know how I could do this? Thanks!

13条回答
做自己的国王
2楼-- · 2020-02-16 07:38

There exists a tool for Windows called Autohotkey that lets you automate almost everything by sending keycodes and mouse clicks. You could write a script that locates your browser window and send the keycode for F5. Assign this script to a global hotkey and you're done.

To get back to your previous window your script would need to remember the currently selected window, refresh the browser and set the focus back to the remembered window.

查看更多
地球回转人心会变
3楼-- · 2020-02-16 07:39

I use MS Ergonomic Keyboard that has a key-macro feature. I programmed Joshs solution in it and it works well, you just have to make sure, the browser is the next application when switsching with alt-tab. There is a cool tool named XRefresh thats just about every developers dream - doesn't work with firefox 4 though.

Edit: But there is an addon "Auto Reload" that does exactly what we need: you specify one or several folders (or files) and firefox refreshes whenever one of the files inside changes.

Edit (2013): PHPStorm has an automatic refresh feature for Google-Chrome. Its awesome: you see the webpage chnge as you type (!) in the IDE. They have a free community edition for OpenSource software developers.

查看更多
Melony?
4楼-- · 2020-02-16 07:42

Thank dogbane and all for share.

Work with Windows 7 you can refresh your browser

Create .bat file and execute

%windir%\SysWOW64\wscript.exe refresh.vbs

and execute .bat with "Run as administrator"

Cannot use CreateObject from VB scripts on Windows 7 x64

:)

查看更多
再贱就再见
5楼-- · 2020-02-16 07:43

There's another solution to this.

Install the FF-Remote-Control plugin in FireFox which will allow you to send commands to the plugin from another machine through network. Instructions on integrating it with VIM are in the documentation which can be used as a template for integration with other editors too. Works only with FF though.

查看更多
\"骚年 ilove
6楼-- · 2020-02-16 07:47

In Windows: Just Press Alt + F5 and get it done. This solution works with more than one browser simultaneously and probably with any Editor/IDE. It was tested with (jEdit, Eclipse, Notepad++)

To accomplish that, install AutoHotKey and run the script below (copy in a text file and change extension to .ahk). There is a portable version here. It was tested with AutoHotKey version is 1.0.48.05

This solution is pretty flexible since you can change Keys, Editors, Browsers and everything else. It come pre configured for Firefox and IE browsers and jEdit, Eclipse editors, but you can easily customize this list.

The varTextEditor and varBrowsers where discovered using "WindowSpy" utility that comes bundled into AutoHotKey.

;###############################################################################
; Save all unsaved documents, refresh all opened browsers and return to text editor
;###############################################################################
!F5::
    ;Configuration vars. Edit here the settings of this script
    ;               jEdit       Eclipse
    varTextEditor = SunAwtFrame,SWT_Window0
    ;varBrowsers = MozillaUIWindowClass,MozillaWindowClass,Chrome_WidgetWin_0,IEFrame,OpWindow,{1C03B488-D53B-4a81-97F8-754559640193}
    ;             Firefox3             Firefox4            Chrome             IEca    Opera    Safari
    varBrowsers = MozillaWindowClass,IEFrame
    ;End of configuration vars.

    WinGetClass, thisWindowClass, A ;Get the active window class

    if (InStr(varTextEditor, thisWindowClass, true, 1) > 0) { ;true = case sensitive
        varTextEditorClass = ahk_class %thisWindowClass%
        if (thisWindowClass = "SunAwtFrame") {
            OutputDebug, ...Saving everything
            ; SetKeyDelay, 100, 100, Play
            Send ^+s  ;Ctrl + Shift + S = Save all
        } else if (thisWindowClass = "SWT_Window0") {
            SendPlay ^s ;Ctrl + S = Save
        }
        Sleep, 500 ;Give some time to the data be recorded on hard disk
    } else {
        MsgBox, 0, Ops!, You must be in on these text editors: (%varTextEditor%) to get this script running, 5
        return
    }

    ;Refresh all opened (and maximized) browsers
    Loop, parse, varBrowsers, `,
    {
        varClasseBrowser = ahk_class %A_LoopField%
        if WinExist(varClasseBrowser) {
            WinGet, winState, MinMax, %varClasseBrowser% ;get window state. -1 = minimized
            if (winState != -1) {
                WinActivate, %varClasseBrowser%
                OutputDebug, ...Refresh browser %A_LoopField%
                Send, {F5}
            }
        }
    }
    ;Return to text editor
    WinActivate, %varTextEditorClass%
return

查看更多
我命由我不由天
7楼-- · 2020-02-16 07:49

In Windows XP, this should work:

  • Create a VBS file called refresh.vbs:

    Set WshShell = WScript.CreateObject("WScript.Shell") 
    WshShell.AppActivate("Firefox")
    WshShell.SendKeys "{F5}"
    WshShell.AppActivate("TextPad")
    
  • Create a shortcut to this file on your desktop.

  • Right-click the shortcut icon and go to Properties.

    • In the General tab, click on the Change button next to "Opens with". Browse to C:\WINDOWS\system32\cscript.exe Select Microsoft Console Based Script Host.

    • In the Shortcut tab, enter a Shortcut key e.g CTRL + ALT + R. In the Run dropdown, select Minimised.

Now, when you hit CTRL + ALT + R, it will refresh the current tab in Firefox.

查看更多
登录 后发表回答