Js
Whenever we see other people on the Web page open, print, forward, save as, back, close this window, disable the right button, such as the implementation of Browser command links, and their own suffering can not be realized, is it regrettable? Do you want to make it happen? How interesting it would be if you could implement a browser command on a Web page! Let's take a look at how to implement a browser menu command with JavaScript code (the following code is debugged in Windows XP browser).
Implementation of commands in the "document (F)" Menu
1, open the implementation of the command
[Format]:d Ocument.execcommand ("open")
[description] This and VB and other programming design in the WebBrowser control of the command somewhat similar, we can also be pondering.
[For example] add between <body></body>:
<a href= "#" Onclick=document.execcommand ("open") > Open </a>
2, the use of Notepad edit the implementation of the command
[Format]:location.replace ("View-source:" +location)
[Description] Open Notepad and display the source code for the page in Notepad.
[For example] add between <body></body>:
<a href= "#" Onclick=location.replace ("View-source:" +location) > Use Notepad edit </a>
3, Save as the implementation of the command
[Format]:d ocument.execcommand ("SaveAs")
[Description] Save the page to a different directory on this site!
[For example] add between <body></body>:
<a href= "#" Onclick=document.execcommand ("SaveAs") > Save As </a>
4, the implementation of the Print command
[Format]:d ocument.execcommand ("print")
[Description] Of course, you must install the printer!
[For example] add between <body></body>:
<a href= "#" Onclick=document.execcommand ("print") > Print </a>
5. The implementation of the close command
[Format]:window.close (); return false
[description] Closes this window.
[For example] add between <body></body>:
<a href= "#" Onclick=window.close (); return false) > close this window </a>
Implementation of commands in the "edit (E)" Menu
Implementation of the full selection command
[Format]:d ocument.execcommand ("SelectAll")
[description] will be the selection of the entire content of the page!
[For example] add between <body></body>:
<a href= "#" Onclick=document.execcommand ("SelectAll") > select All </a>
implementation of the commands in the View (V) menu
1, implementation of the Refresh command
[format]:location.reload () or history.go (0)
[description] The browser opens this page again.
[Example] <body></body> join:
<a href= "#" Onclick=location.reload () > Refresh </a>
or join:< A href= "#" Onclick=history.go (0) > Refresh </a>
2, implementation of the source File command
[format]:location.replace ("View-source:" + Location)
[description] To view the source code for the Web page.
[Example] add between <body></body>:
<a href= "#" Onclick=location.replace ("View-source:" +location) > View the source file </a>
3, implementation of the full Screen command
[format]:window.open (document.location, URL, fullscreen)
[description] Displays this page in full screen.
[examples] add between <body></body>:
<a href= "#" Onclick=window.open (document.location, "url", " Fullscreen ") > Full-screen display </a>
Implementation of commands in the "Favorites (A)" Menu
1. Add to the implementation of the Favorites folder command
[Format]:window.external.addfavorite (' url ', ' "Site name ')
[Description] Add this page to the Favorites folder.
[For example] add between <body></body>:
<a href= "Java script:window.external.AddFavorite (' http://oh.jilinfarm.com ', ' Hu Ming's personal home page ')" > Add to Favorites </a>
2. Organize the implementation of the collection folder command
[Format]:window.external.showbrowserui ("Organizefavorites", NULL)
[Description] Open the Organize Favorites dialog box.
[For example] add between <body></body>:
<a href= "#" Onclick=window.external.showbrowserui ("organizefavorites", NULL) > Organize Favorites </a>
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.
[For example] add between <body></body>:
<a href= "#" Onclick=window.external.showbrowserui ("privacysettings", null) >internet option </a>
Implementation of commands in the "toolbar"
1, the implementation of the forward command
[Format]history.go (1) or History.forward ()
[Description] The browser opens the next page.
[For example] add between <body></body>:
<a href= "#" Onclick=history.go (1) > Forward </a>
or add: <a href= "#" Onclick=history.forward () > Forward </a>
2, the implementation of the back command
[Format]:history.go (-1) or history.back ()
[description] The browser returns the previous browsed page.
[For example] add between <body></body>:
<a href= "#" Onclick=history.go ( -1) > Back </a>
or add: <a href= "#" Onclick=history.back () > Back </a>
3, the implementation of the Refresh command
[Format]:d ocument.reload () or history.go (0)
[Description] The browser opens this page again.
[For example] add between <body></body>:
<a href= "#" Onclick=location.reload () > Refresh </a>
or add: <a href= "#" Onclick=history.go (0) > Refresh </a>
VII. implementation of other orders
Implementation of the command to turn off this window periodically
[Format]:settimeout (Window.close (), closed time)
[description] Closes this window.
[For example] add between <body></body>:
<a href= "#" Onclick=settimeout (Window.close (), 3000) >3 seconds close this window </a>
If you also organize other use JavaScript to achieve the command, may wish to contribute to share with you.
"Attached" to facilitate the reader, the following will list all the instance code, you can put them in an HTML file, and then preview the effect.
<a href= "#" Onclick=document.execcommand ("open") > Open </A>CHR &chr (10)
<a href= "#" Onclick=location.replace ("View-source:" +location) > Use Notepad to edit </A>CHR (10)
<a href= "#" Onclick=document.execcommand ("SaveAs") > Save as </A>CHR (10)
<a href= "#" Onclick=document.execcommand ("print") > Print </A>CHR (10)
<a href= "#" Onclick=window.close (); return false) > close this window </a>chr &CHR (10)
<a href= "#" Onclick=document.execcommand ("SelectAll") > Total election </A>CHR (10)
<a href= "#" Onclick=location.reload () > Refresh </a> <a href= "#" Onclick=history.go (0) > Refresh </A>CHR (13 ) &CHR (10)
<a href= "#" Onclick=location.replace ("View-source:" +location) > View source Files </a> chr (10)
<a href= "#" Onclick=window.open (document.location, "url", "fullscreen") > Full-screen display </a> chr (10)
<a href= "Java script:window.external.AddFavorite (' http://homepage.yesky.com ', ' Tenkine") "> Add to Favorites </a> Chr (&CHR) (10)
<a href= "#" Onclick=window.external.showbrowserui ("organizefavorites", NULL) > Organize favorites </a> chr &CHR (10)
<a href= "#" Onclick=window.external.showbrowserui ("privacysettings", null) >internet option </a> chr (%) & CHR (10)
<a href= "#" Onclick=history.go (1) > Forward 1</a> <a href= "#" Onclick=history.forward () > Forward 2</A>CHR ( &CHR (10)
<a href= "#" Onclick=history.go ( -1) > Back 1</a> <a href= "#" Onclick=history.back () > Back 2</A>CHR (13 ) &CHR (10)
<a href= "#" Onclick=settimeout (Window.close (), 3000) >3 seconds close this window </A>CHR (10)