Javascript实现浏览器菜单命令
一、【文件(F)】菜单中的命令的实现
1、〖打开〗命令的实现
[格式]:document.execCommand("open")
[说明]这跟VB等编程设计中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。
[举例]在<body></body>之间加入:
<a href="#" οnclick=document.execCommand("open")>打开</a>
2、〖使用 记事本 编辑〗命令的实现
[格式]:location.replace("view-source:"+location)
[说明]打开记事本,在记事本中显示该网页的源代码。
[举例]在<body></body>之间加入:
<a href="#" οnclick=location.replace("view-source:"+location)>使用 记事本 编辑</a>
3、〖另存为〗命令的实现
[格式]:document.execCommand("saveAs")
[说明]将该网页保存到本地盘的其它目录!
[举例]在<body></body>之间加入:
<a href="#" οnclick=document.execCommand("saveAs")>另存为</a>
4、〖打印〗命令的实现
[格式]:document.execCommand("print")
[说明]当然,你必须装了打印机!
[举例]在<body></body>之间加入:
<a href="#" οnclick=document.execCommand("print")>打印</a>
5、〖关闭〗命令的实现
[格式]:window.close();return false
[说明]将关闭本窗口。
[举例]在<body></body>之间加入:
<a href="#" οnclick=window.close();return false)>关闭本窗口</a>
二、【编辑(E)】菜单中的命令的实现
〖全选〗命令的实现
[格式]:document.execCommand("selectAll")
[说明]将选种网页中的全部内容!
[举例]在<body></body>之间加入:
<a href="#" οnclick=document.execCommand("selectAll")>全选</a>
三、【查看(V)】菜单中的命令的实现
1、〖刷新〗命令的实现
[格式]:location.reload() 或 history.go(0)
[说明]浏览器重新打开本页。
[举例]在<body></body>之间加入:
<a href="#" οnclick=location.reload()>刷新</a>
或加入:<a href="#" οnclick=history.go(0)>刷新</a>
2、〖源文件〗命令的实现
[格式]:location.replace("view-source:"+location)
[说明]查看该网页的源代码。
[举例]在<body></body>之间加入:
<a href="#" οnclick=location.replace("view-source:"+location)>查看源文件</a>
3、〖全屏显示〗命令的实现
[格式]:window.open(document.location,"url","fullscreen")
[说明]全屏显示本页。
[举例]在<body></body>之间加入:
<a href="#" οnclick=window.open(document.location,"url","fullscreen")>全屏显示</a>
四、【收藏(A)】菜单中的命令的实现
1、〖添加到收藏夹〗命令的实现
[格式]:window.external.AddFavorite('url', '“网站名”)
[说明]将本页添加到收藏夹。
[举例]在<body></body>之间加入:
<a href="javascript:window.external.AddFavorite('[url]http://oh.jilinfarm.com[/url]', '胡明新的个人主页')">添加到收藏夹</a>
2、〖整理收藏夹〗命令的实现
[格式]:window.external.showBrowserUI("OrganizeFavorites",null)
[说明]打开整理收藏夹对话框。
[举例]在<body></body>之间加入:
<a href="#" οnclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夹</a>
五、【工具(T)】菜单中的命令的实现
〖internet选项〗命令的实现
[格式]:window.external.showBrowserUI("PrivacySettings",null)
[说明]打开internet选项对话框。
[举例]在<body></body>之间加入:
<a href="#" οnclick=window.external.showBrowserUI("PrivacySettings",null)>internet选项</a>
六、【工具栏】中的命令的实现
1、〖前进〗命令的实现
[格式]history.go(1) 或 history.forward()
[说明]浏览器打开后一个页面。
[举例]在<body></body>之间加入:
<a href="#" οnclick=history.go(1)>前进</a>
或加入:<a href="#" οnclick=history.forward()>前进</a>
2、〖后退〗命令的实现
[格式]:history.go(-1) 或 history.back()
[说明]浏览器返回上一个已浏览的页面。
[举例]在<body></body>之间加入:
<a href="#" οnclick=history.go(-1)>后退</a>
或加入:<a href="#" οnclick=history.back()>后退</a>
3、〖刷新〗命令的实现
[格式]:document.reload() 或 history.go(0)
[说明]浏览器重新打开本页。
[举例]在<body></body>之间加入:
<a href="#" οnclick=location.reload()>刷新</a>
或加入:<a href="#" οnclick=history.go(0)>刷新</a>
七、其它命令的实现
〖定时关闭本窗口〗命令的实现
[格式]:settimeout(window.close(),关闭的时间)
[说明]将关闭本窗口。
[举例]在<body></body>之间加入:
<a href="#" οnclick=settimeout(window.close(),3000)>3秒关闭本窗口</a>
如果大家还整理出其他用Javascript实现的命令,不妨投稿来和大家分享。
【附】为了方便读者,下面将列出所有实例代码,你可以把它们放到一个html文件中,然后预览效果。
<a href="#" οnclick=document.execCommand("open")>打开</a><br>
<a href="#" οnclick=location.replace("view-source:"+location)>使用 记事本 编辑</a><br>
<a href="#" οnclick=document.execCommand("saveAs")>另存为</a><br>
<a href="#" οnclick=document.execCommand("print")>打印</a><br>
<a href="#" οnclick=window.close();return false)>关闭本窗口</a><br>
<a href="#" οnclick=document.execCommand("selectAll")>全选</a><br>
<a href="#" οnclick=location.reload()>刷新</a> <a href="#" οnclick=history.go(0)>刷新</a><br>
<a href="#" οnclick=location.replace("view-source:"+location)>查看源文件</a> <br>
<a href="#" οnclick=window.open(document.location,"url","fullscreen")>全屏显示</a> <br>
<a href="javascript:window.external.AddFavorite('[url]http://homepage.yesky.com[/url]', '天极网页陶吧')">添加到收藏夹</a> <br>
<a href="#" οnclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夹</a> <br>
<a href="#" οnclick=window.external.showBrowserUI("PrivacySettings",null)>internet选项</a> <br>
<a href="#" οnclick=history.go(1)>前进1</a> <a href="#" οnclick=history.forward()>前进2</a><br>
<a href="#" οnclick=history.go(-1)>后退1</a> <a href="#" οnclick=history.back()>后退2</a><br>
<a href="#" οnclick=settimeout(window.close(),3000)>3秒关闭本窗口</a><br>
转载于:https://blog.51cto.com/chensanxin/42329
Javascript实现浏览器菜单命令相关推荐
- 用Javascript代码实现浏览器菜单命令(以下代码在 Windows XP下的浏览器中调试通过
每当我们看到别人网页上的打开.打印.前进.另存为.后退.关闭本窗口.禁用右键等实现浏览器命令的链接,而自己苦于不能实现时,是不是感到很遗憾?是不是也想实现?如果能在网页上能实现浏览器的命令,将是多么有 ...
- JavaScript实现浏览器菜单的一些功能
■打开■ <input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开> < ...
- Javascript:阻止浏览器默认右键事件,并显示定制内容
在逛一些知名图片社区的时候,遇到自己心怡的图片,想要右键另存的时候,默认的浏览器菜单不见了,却出现了如:[©kevin版权所有]之类的信息: 今天在看Javascript事件默认行为相关的知识,所以, ...
- jquery和javascript屏蔽右键菜单及阻止事件冒泡
jquery屏蔽右键菜单 $(document).ready(function(){$(document).bind("contextmenu",function(e){retur ...
- Chrome浏览器启动命令行参数
Chrome浏览器启动命令行参数 https://peter.sh/experiments/chromium-command-line-switches/#auto-open-devtools-for ...
- [js]windows下通过命令行运行javascript脚本,支持命令行参数
windows下通过命令行运行javascript脚本,支持命令行参数 js作为最受欢迎的语言,以其方便.通用.功能强大的特点,可以给大家在实际使用的过程中带来很大的便利. 下面是本文从实际应用的角度 ...
- JavaScript 复制浏览器地址
点击button 复制当前窗口的 url html <button onclick="copyUrl()"></button> <input type ...
- 使用JavaScript在浏览器中进行图像分类
by Kevin Scott 凯文·斯科特(Kevin Scott) 使用JavaScript在浏览器中进行图像分类 (Image Classification in the Browser with ...
- javascript与浏览器学习(一)
待学习---- 20160421 标题:JavaScript中浏览器兼容问题 博客地址:http://www.cnblogs.com/DF-fzh/p/5408241.html 简单 ...
最新文章
- paypal提现软件_PayPal软件工程师生命中的一天
- javaweb 后台知识点
- 您可能不知道的ASP.Net小技巧
- Flink on Yarn运行机制
- leetcode877.StoneGame
- java实验指导答案华软_Java核心编程技术实验指导教程
- java wait 执行顺序_JAVA 的wait(), notify()与synchronized同步机制
- 多线程之实现同步的信号量Semaphore
- windows上搭建NFS服务器--haneWIN,Linux客户端挂载
- acm竞赛题库与解析
- lg相乘公式_lg函数(log的公式大全)
- 量子力学考研书籍介绍
- 人脸识别与美颜算法实战-图像特效
- 【Excel 2013 数据透视表 学习】一、创建数据透视表
- 解决The authenticity of host can’t be established ECDSA key fingerprint is SHA256
- Linux 2.6下Driver开发的34个变化[转贴]
- 诊断和响应故障_恢复表和表分区
- python 任务管理系统_python bottle框架开发任务管理系统 V_1.0版
- mysql入库出库触发器_oracle 触发器 实现出入库
- 计算机理论导引 期末,计算机理论导引实验报告_CFG是P成员