js手册学习--Image 对象--Location 对象--Navigator

来源:互联网 发布:ie8中文版官方mac 编辑:程序博客网 时间:2024/05/16 20:27

转载:http://www.w3school.com.cn/example/hdom_examples.asp


1.1更改图像的高度和宽度

<html><head><script type="text/javascript">function changeSize(){document.getElementById("compman").height="270"document.getElementById("compman").width="164"}</script></head><body><img id="compman" src="/i/eg_bulbon.gif" /><br /><br /><input type="button" onclick="changeSize()" value="改变图像的高度和宽度"></body></html>

2.1更改图像的 src

<html><head><script type="text/javascript">function changeSrc()  {  document.getElementById("myImage").src="/i/eg_smile.gif"  }</script></head><body><img id="myImage" src="/i/eg_bulbon.gif" /><br /><br /><input type="button" onclick="changeSrc()" value="改变图像"></body></html>

Location 对象


3.1把用户带到一个新的地址

<html><head><script type="text/javascript">function currLocation(){alert(window.location)}function newLocation(){window.location="/index.html"}</script></head><body><input type="button" onclick="currLocation()" value="显示当前的 URL"><input type="button" onclick="newLocation()" value="改变 URL"></body></html>

4.1重新加载文档

<html><head><script type="text/javascript">function reloadPage(){window.location.reload();}</script></head><body><input type="button" value="重新加载页面" onclick="reloadPage()" /></body></html>

5.1跳出框架

<html><head><script type="text/javascript">function breakout()  {  if (window.top!=window.self)     {    window.top.location="/example/hdom/tryjs_breakout.htm"    }  }</script></head><body><input type="button" onclick="breakout()" value="跳出框架!"></body></html>

Navigator

6.1检测访问者的浏览器和版本号

<html><body><script type="text/javascript">var browser=navigator.appNamevar b_version=navigator.appVersionvar version=parseFloat(b_version)document.write("浏览器名称:"+ browser)document.write("<br />")document.write("浏览器版本:"+ version)</script></body></html>

7.1有关访问者的浏览器的更多信息

<html><body><script type="text/javascript">document.write("<p>浏览器:")document.write(navigator.appName + "</p>")document.write("<p>浏览器版本:")document.write(navigator.appVersion + "</p>")document.write("<p>代码:")document.write(navigator.appCodeName + "</p>")document.write("<p>平台:")document.write(navigator.platform + "</p>")document.write("<p>Cookies 启用:")document.write(navigator.cookieEnabled + "</p>")document.write("<p>浏览器的用户代理报头:")document.write(navigator.userAgent + "</p>")</script></body></html>

8.1有关访问者的浏览器的全部细节

<html><body><script type="text/javascript">var x = navigator;document.write("CodeName=" + x.appCodeName);document.write("<br />");document.write("MinorVersion=" + x.appMinorVersion);document.write("<br />");document.write("Name=" + x.appName);document.write("<br />");document.write("Version=" + x.appVersion);document.write("<br />");document.write("CookieEnabled=" + x.cookieEnabled);document.write("<br />");document.write("CPUClass=" + x.cpuClass);document.write("<br />");document.write("OnLine=" + x.onLine);document.write("<br />");document.write("Platform=" + x.platform);document.write("<br />");document.write("UA=" + x.userAgent);document.write("<br />");document.write("BrowserLanguage=" + x.browserLanguage);document.write("<br />");document.write("SystemLanguage=" + x.systemLanguage);document.write("<br />");document.write("UserLanguage=" + x.userLanguage);</script></body></html>

9.1根据浏览器来提醒用户

<html><head><script type="text/javascript">function detectBrowser(){var browser=navigator.appNamevar b_version=navigator.appVersionvar version=parseFloat(b_version)if ((browser=="Netscape"||browser=="Microsoft Internet Explorer") && (version>=4))  {alert("您的浏览器已经很棒了!")}else  {alert("您的浏览器需要升级了!")}}</script></head><body onload="detectBrowser()"></body></html>




原创粉丝点击