JavaScript implements browser menu commands

Source: Internet
Author: User

When 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 the browser command link, and their own suffering can not be realized, is it regrettable? Do you want to make it? What a fun thing to do if you can implement a browser's command on a webpage! Let's take a look at how to implement a browser menu command using JavaScript code (the following code is debugged in a browser under Windows XP).

I. Implementation of commands in the "file (F)" Menu
1. Implementation of the Open command
[Format]:d Ocument.execcommand ("open")
[note] This is similar to the commands in the WebBrowser control in programming design such as VB, we can also follow this to ponder.
[For example] to 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)
[Description] Open Notepad and display the source code for the page in Notepad.
[For example] to add between <body></body>:
<a href= "#" Onclick=location.replace ("View-source:" +location) > Edit with Notepad </a>
3. Implementation of the Save As command
[Format]:d ocument.execcommand ("SaveAs")
[Note] Save this page to another directory on this site!
[For example] to 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 have to install a printer!
[For example] to add between <body></body>:
<a href= "#" Onclick=document.execcommand ("print") > Printing </a>
5. Implementation of the Close command
[Format]:window.close (); return false
[description] will close this window.
[For example] to add between <body></body>:
<a href= "#" Onclick=window.close (); return false) > close this window </a>

II. implementation of commands in the "edit (E)" Menu
Implementation of the Select All command
[Format]:d ocument.execcommand ("SelectAll")
[description] will be the selection of all the contents of the page!
[For example] to add between <body></body>:
<a href= "#" Onclick=document.execcommand ("SelectAll") > select All </a>

Three, "View (V)" menu of the implementation of the command  
 1, the implementation of the Refresh command  
 [format]:location.reload ()   or  history.go ( 0)  
 [description] The browser re-opens this page. &NBSP,
 [example] to join between <body></body>:  
 <a href= "#"  onclick= Location.reload () > Refresh </a> 
  or join: <a href= "#"  onclick=history.go (0) > Refresh </  a> 
 2, the implementation of the source File command  
 [format]:location.replace ("View-source:" +location)  
 [description] View the source code for the page. &NBSP,
 [example] to join between <body></body>:  
 <a href= "#"  onclick= Location.replace ("View-source:" +location) > View source file </a> 
 3, Full screen display command implementation  
 [format]: window.open (document.location, "url", "fullscreen")  
 [Description] This page is displayed in full screen. &NBSP,
 [example] to join between <body></body>:  
 <a href= "#"  onclick= window.open (document.location, "url", "fullscreen") > Full-screen display </a> 

Iv. The implementation of the commands in the Favorites (A) menu  
 1, the implementation of the Add to Favorites command  
 [format]:window.external.addfavorite (' URL ',   ' website name ')  
 [description] Add this page to favorites. &NBSP,
 [example]:  
 <a href= "Java script: Window.external.AddFavorite (' http://oh.jilinfarm.com ',  ' Hu Ming's personal homepage ') ' > Add to Favorites </a> 
 2, Implementation of the Organize Favorites command  
 [format]:window.external.showbrowserui ("Organizefavorites", null)  
 [description] Opens the Organize Favorites dialog box. &NBSP,
 [example] to join between <body></body>:  
 <a href= "#"  onclick= Window.external.showBrowserUI ("organizefavorites", NULL) > Organize favorites </a> 

V. Implementation of commands in the "Tools (T)" Menu
Implementation of the 〖internet option command
[Format]:window.external.showbrowserui ("Privacysettings", NULL)
[Description] Opens the Internet Options dialog box.
[For example] to add between <body></body>:
<a href= "#" Onclick=window.external.showbrowserui ("privacysettings", null) >internet options </a>

VI. implementation of the commands in the toolbar
1, the implementation of the forward command
[Format]history.go (1) or History.forward ()
[Description] The browser opens after a page.
[For example] to add between <body></body>:
<a href= "#" Onclick=history.go (1) > Forward </a>
or join: <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 to the previous browsed page.
[For example] to add between <body></body>:
<a href= "#" Onclick=history.go ( -1) > Back </a>
or join: <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] to add between <body></body>:
<a href= "#" Onclick=location.reload () > Refresh </a>
or join: <a href= "#" Onclick=history.go (0) > Refresh </a>

VII. implementation of OTHER commands
Implementation of the timed close this window command
[Format]:settimeout (Window.close (), closed time)
[description] will close this window.
[For example] to add between <body></body>:
<a href= "#" Onclick=settimeout (Window.close (), up) >3 sec close this window </a>

If you're also sorting out other JavaScript-implemented commands, you might want to contribute and share them.
"Attached" for the convenience of the reader, the following will list all the instance codes, you can put them in an HTML file, and then preview the effect.
<a href= "#" Onclick=document.execcommand ("open") > Open </a><br>
<a href= "#" Onclick=location.replace ("View-source:" +location) > Edit with Notepad </a><br>
<a href= "#" Onclick=document.execcommand ("SaveAs") > Save As </a><br>
<a href= "#" Onclick=document.execcommand ("print") > Printing </a><br>
<a href= "#" Onclick=window.close (); return false) > close this window </a><br>
<a href= "#" Onclick=document.execcommand ("SelectAll") > select All </a><br>
<a href= "#" Onclick=location.reload () > Refresh </a> <a href= "#" Onclick=history.go (0) > Refresh </a><br >
<a href= "#" Onclick=location.replace ("View-source:" +location) > View source Files </a> <br>
<a href= "#" Onclick=window.open (document.location, "url", "fullscreen") > Full screen </a> <br>
<a href= "Java script:window.external.AddFavorite (' http://homepage.yesky.com ', ' Yesky page Pottery bar ')" > Add to Favorites </a> <br>
<a href= "#" Onclick=window.external.showbrowserui ("organizefavorites", NULL) > Organize Favorites </a> <br>
<a href= "#" Onclick=window.external.showbrowserui ("privacysettings", null) >internet options </a> <br>
<a href= "#" Onclick=history.go (1) > Forward 1</a> <a href= "#" Onclick=history.forward () > Forward 2</a>< Br>
<a href= "#" Onclick=history.go ( -1) > Back 1</a> <a href= "#" Onclick=history.back () > Back 2</a><br >
<a href= "#" Onclick=settimeout (Window.close (), up) >3 sec close this window </a><br>

JavaScript implements browser menu commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.