一、【文件(F)】菜單中的命令的實(shí)現(xiàn)
1、〖打開(kāi)〗命令的實(shí)現(xiàn)
[格式]:document.execCommand("open")
[說(shuō)明]這跟VB等編程設(shè)計(jì)中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。
[舉例]在<body></body>之間加入:
<a href="#" onclick=document.execCommand("open")>打開(kāi)</a>
2、〖使用 記事本 編輯〗命令的實(shí)現(xiàn)
[格式]:location.replace("view-source:"+location)
[說(shuō)明]打開(kāi)記事本,在記事本中顯示該網(wǎng)頁(yè)的源代碼。
[舉例]在<body></body>之間加入:
<a href="#" onclick=location.replace("view-source:"+location)>使用 記事本 編輯</a>
3、〖另存為〗命令的實(shí)現(xiàn)
[格式]:document.execCommand("saveAs")
[說(shuō)明]將該網(wǎng)頁(yè)保存到本地盤(pán)的其它目錄!
[舉例]在<body></body>之間加入:
<a href="#" onclick=document.execCommand("saveAs")>另存為</a>
4、〖打印〗命令的實(shí)現(xiàn)
[格式]:document.execCommand("print")
[說(shuō)明]當(dāng)然,你必須裝了打印機(jī)!
[舉例]在<body></body>之間加入:
<a href="#" onclick=document.execCommand("print")>打印</a>
5、〖關(guān)閉〗命令的實(shí)現(xiàn)
[格式]:window.close();return false
[說(shuō)明]將關(guān)閉本窗口。
[舉例]在<body></body>之間加入:
<a href="#" onclick=window.close();return false)>關(guān)閉本窗口</a>
二、【編輯(E)】菜單中的命令的實(shí)現(xiàn)
〖全選〗命令的實(shí)現(xiàn)
[格式]:document.execCommand("selectAll")
[說(shuō)明]將選種網(wǎng)頁(yè)中的全部?jī)?nèi)容!
[舉例]在<body></body>之間加入:
<a href="#" onclick=document.execCommand("selectAll")>全選</a>
三、【查看(V)】菜單中的命令的實(shí)現(xiàn)
1、〖刷新〗命令的實(shí)現(xiàn)
[格式]:location.reload() 或 history.go(0)
[說(shuō)明]瀏覽器重新打開(kāi)本頁(yè)。
[舉例]在<body></body>之間加入:
<a href="#" onclick=location.reload()>刷新</a>
或加入:<a href="#" onclick=history.go(0)>刷新</a>
2、〖源文件〗命令的實(shí)現(xiàn)
[格式]:location.replace("view-source:"+location)
[說(shuō)明]查看該網(wǎng)頁(yè)的源代碼。
[舉例]在<body></body>之間加入:
<a href="#" onclick=location.replace("view-source:"+location)>查看源文件</a>
3、〖全屏顯示〗命令的實(shí)現(xiàn)
[格式]:window.open(document.location,"url","fullscreen")
[說(shuō)明]全屏顯示本頁(yè)。
[舉例]在<body></body>之間加入:
<a href="#" onclick=window.open(document.location,"url","fullscreen")>全屏顯示</a>
四、【收藏(A)】菜單中的命令的實(shí)現(xiàn)
1、〖添加到收藏夾〗命令的實(shí)現(xiàn)
[格式]:window.external.AddFavorite('url', '“網(wǎng)站名”)
[說(shuō)明]將本頁(yè)添加到收藏夾。
[舉例]在<body></body>之間加入:
<a href="Java script:window.external.AddFavorite('http://oh.jilinfarm.com', '胡明新的個(gè)人主頁(yè)')">添加到收藏夾</a>
2、〖整理收藏夾〗命令的實(shí)現(xiàn)
[格式]:window.external.showBrowserUI("OrganizeFavorites",null)
[說(shuō)明]打開(kāi)整理收藏夾對(duì)話(huà)框。
[舉例]在<body></body>之間加入:
<a href="#" onclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夾</a>
五、【工具(T)】菜單中的命令的實(shí)現(xiàn)
〖internet選項(xiàng)〗命令的實(shí)現(xiàn)
[格式]:window.external.showBrowserUI("PrivacySettings",null)
[說(shuō)明]打開(kāi)internet選項(xiàng)對(duì)話(huà)框。
[舉例]在<body></body>之間加入:
<a href="#" onclick=window.external.showBrowserUI("PrivacySettings",null)>internet選項(xiàng)</a>
六、【工具欄】中的命令的實(shí)現(xiàn)
1、〖前進(jìn)〗命令的實(shí)現(xiàn)
[格式]history.go(1) 或 history.forward()
[說(shuō)明]瀏覽器打開(kāi)后一個(gè)頁(yè)面。
[舉例]在<body></body>之間加入:
<a href="#" onclick=history.go(1)>前進(jìn)</a>
或加入:<a href="#" onclick=history.forward()>前進(jìn)</a>
2、〖后退〗命令的實(shí)現(xiàn)
[格式]:history.go(-1) 或 history.back()
[說(shuō)明]瀏覽器返回上一個(gè)已瀏覽的頁(yè)面。
[舉例]在<body></body>之間加入:
<a href="#" onclick=history.go(-1)>后退</a>
或加入:<a href="#" onclick=history.back()>后退</a>
3、〖刷新〗命令的實(shí)現(xiàn)
[格式]:document.reload() 或 history.go(0)
[說(shuō)明]瀏覽器重新打開(kāi)本頁(yè)。
[舉例]在<body></body>之間加入:
<a href="#" onclick=location.reload()>刷新</a>
或加入:<a href="#" onclick=history.go(0)>刷新</a>
七、其它命令的實(shí)現(xiàn)
〖定時(shí)關(guān)閉本窗口〗命令的實(shí)現(xiàn)
[格式]:settimeout(window.close(),關(guān)閉的時(shí)間)
[說(shuō)明]將關(guān)閉本窗口。
[舉例]在<body></body>之間加入:
<a href="#" onclick=settimeout(window.close(),3000)>3秒關(guān)閉本窗口</a>
如果大家還整理出其他用javascript實(shí)現(xiàn)的命令,不妨投稿來(lái)和大家分享。
【附】為了方便讀者,下面將列出所有實(shí)例代碼,你可以把它們放到一個(gè)html文件中,然后預(yù)覽效果。
<a href="#" onclick=document.execCommand("open")>打開(kāi)</a><br>
<a href="#" onclick=location.replace("view-source:"+location)>使用 記事本 編輯</a><br>
<a href="#" onclick=document.execCommand("saveAs")>另存為</a><br>
<a href="#" onclick=document.execCommand("print")>打印</a><br>
<a href="#" onclick=window.close();return false)>關(guān)閉本窗口</a><br>
<a href="#" onclick=document.execCommand("selectAll")>全選</a><br>
<a href="#" onclick=location.reload()>刷新</a> <a href="#" onclick=history.go(0)>刷新</a><br>
<a href="#" onclick=location.replace("view-source:"+location)>查看源文件</a> <br>
<a href="#" onclick=window.open(document.location,"url","fullscreen")>全屏顯示</a> <br>
<a href="Java script:window.external.AddFavorite('http://homepage.yesky.com', '天極網(wǎng)頁(yè)陶吧')">添加到收藏夾</a> <br>
<a href="#" onclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夾</a> <br>
<a href="#" onclick=window.external.showBrowserUI("PrivacySettings",null)>internet選項(xiàng)</a> <br>
<a href="#" onclick=history.go(1)>前進(jìn)1</a> <a href="#" onclick=history.forward()>前進(jìn)2</a><br>
<a href="#" onclick=history.go(-1)>后退1</a> <a href="#" onclick=history.back()>后退2</a><br>
<a href="#" onclick=settimeout(window.close(),3000)>3秒關(guān)閉本窗口</a><br>
"打開(kāi),另存為,屬性,打印"等14個(gè)JS代碼
http://www.weiw.com 2003-8-19 偉網(wǎng)動(dòng)力
■打開(kāi)■
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打開(kāi)>
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■另存為■
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存為><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■屬性■
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=屬性><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■打印■
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■頁(yè)面設(shè)置■
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=頁(yè)面設(shè)置><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
■刷新■
<input type=button value=刷新 name=refresh onclick="window.location.reload()">
■導(dǎo)入收藏■
<input type="button" name="Button" value="導(dǎo)入收藏夾" onClick=window.external.ImportExportFavorites(true,);>
■導(dǎo)出收藏■
<input type="button" name="Button3" value="導(dǎo)出收藏夾" onClick=window.external.ImportExportFavorites(false,);>
■加入收藏■
<INPUT name=Button2 onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夾>
■整理收藏夾■
<INPUT name=Submit2 onclick="window.external.ShowBrowserUI(OrganizeFavorites, null)" type=button value=整理收藏夾>
■查看原文件■
<INPUT name=Button onclick=window.location = "view-source:" + window.location.href type=button value=查看源文件>
■語(yǔ)言設(shè)置■
<INPUT name=Button onclick="window.external.ShowBrowserUI(LanguageDialog, null)" type=button value=語(yǔ)言設(shè)置>
■前進(jìn)■
<INPUT name=Submit onclick=history.go(1) type=submit value=前進(jìn)>
■后退■
<INPUT name=Submit2 onclick=history.go(-1) type=submit value=后退>