Whenever we see links on other people's web pages that implement browser commands such as open, print, forward, save as, back, close this window, disable right-click, etc., but we are unable to implement them ourselves, do we feel regretful? Do you also want to achieve it? How interesting it would be if browser commands could be implemented on the web page! Let's take a look at how to use Javascript code to implement browser menu commands (the following code has been debugged in the browser under Windows XP), Wulin.com, www.vevb.com.
1. Implementation of commands in the [File (F)] menu
1. Implementation of the "Open" command
[Format]:document.execCommand(open)
[Explanation] This is somewhat similar to the commands in the webbrowser control in VB and other programming designs. You can also think about it based on this.
[Example] Add between <body></body>:
<a href=# onclick=document.execCommand(open)>Open</a>
2. Implementation of the "Edit with Notepad" command
[Format]:location.replace(view-source:+location)
[Instructions] Open Notepad and display the source code of the web page in Notepad.
[Example] Add between <body></body>:
<a href=# onclick=location.replace(view-source:+location)>Edit with Notepad</a>
3. Implementation of the "Save as" command
[Format]:document.execCommand(saveAs)
[Instructions] Save this web page to another directory on the local disk!
[Example] Add between <body></body>:
<a href=# onclick=document.execCommand(saveAs)>Save As</a>
4. Implementation of 〖Print〗 command
[Format]:document.execCommand(print)
[Instructions] Of course, you must have a printer installed!
[Example] Add between <body></body>:
<a href=# onclick=document.execCommand(print)>Print</a>
5. Implementation of the "Close" command
[Format]:window.close();return false
[Description] This window will be closed.
[Example] Add between <body></body>:
<a href=# onclick=window.close();return false)>Close this window</a>
2. Implementation of commands in the [Edit (E)] menu
Implementation of "Select All" command
[Format]:document.execCommand(selectAll)
[Description] All content in the web page will be selected!
[Example] Add between <body></body>:
<a href=# onclick=document.execCommand(selectAll)>Select All</a>
3. Implementation of commands in the [View (V)] menu
1. Implementation of the "Refresh" command
[Format]:location.reload() or history.go(0)
[Instructions] Reopen this page in your browser.
[Example] Add between <body></body>:
<a href=# onclick=location.reload()>Refresh</a>
Or add:<a href=# onclick=history.go(0)>Refresh</a>
2. Implementation of the 〖Source File〗 command
[Format]:location.replace(view-source:+location)
[Instructions] View the source code of this web page.
[Example] Add between <body></body>:
<a href=# onclick=location.replace(view-source:+location)>View source file</a>
3. Implementation of the 〖Full Screen Display〗 command
[Format]:window.open(document.location,url,fullscreen)
[Instructions] Display this page in full screen.
[Example] Add between <body></body>:
<a href=# onclick=window.open(document.location,url,fullscreen)>Full screen display</a>
4. Implementation of commands in the [Collection (A)] menu
1. Implementation of the "Add to Favorites" command
[Format]:window.external.AddFavorite('url', 'website name)
[Instructions] Add this page to favorites.
[Example] Add between <body></body>:
<a href=javascript:window.external.AddFavorite('http://oh.jilinfarm.com', 'Hu Mingxin's personal homepage')>Add to favorites</a>
2. Implementation of the "Organize Favorites" command
[Format]:window.external.showBrowserUI(OrganizeFavorites,null)
[Description] Open the Organize Favorites dialog box.
[Example] Add between <body></body>:
<a href=# onclick=window.external.showBrowserUI(OrganizeFavorites,null)>Organize favorites</a>
5. Implementation of commands in the [Tools (T)] menu
Implementation of the 〖internet option〗 command
[Format]:window.external.showBrowserUI(PrivacySettings,null)
[Description] Open the internet options dialog box.
[Example] Add between <body></body>:
<a href=# onclick=window.external.showBrowserUI(PrivacySettings,null)>internet options</a>
6. Implementation of commands in [Toolbar]
1. Implementation of 〖Forward〗 command
[Format]history.go(1) or history.forward()
[Explanation] The browser opens the next page.
[Example] Add between <body></body>:
<a href=# onclick=history.go(1)>Forward</a>
Or join:<a href=# onclick=history.forward()>Forward</a>
2. Implementation of the "Back" command
[Format]:history.go(-1) or history.back()
[Description] The browser returns to the previous viewed page.
[Example] Add between <body></body>:
<a href=# onclick=history.go(-1)>Back</a>
Or add:<a href=# onclick=history.back()>Back</a>
3. Implementation of the "Refresh" command
[Format]:document.reload() or history.go(0)
[Instructions] Reopen this page in your browser.
[Example] Add between <body></body>:
<a href=# onclick=location.reload()>Refresh</a>
Or add:<a href=# onclick=history.go(0)>Refresh</a>
7. Implementation of other commands
Implementation of the "Close this window regularly" command
[Format]:settimeout(window.close(), closing time)
[Description] This window will be closed.
[Example] Add between <body></body>:
<a href=# onclick=setTimeout(window.close(),3000)>Close this window in 3 seconds</a>