天天看點

js手冊學習--Image 對象--Location 對象--Navigator

轉載: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" οnclick="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" οnclick="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" οnclick="currLocation()" value="顯示目前的 URL">
<input type="button" οnclick="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="重新加載頁面" οnclick="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" οnclick="breakout()" value="跳出架構!">

</body>
</html>
           

Navigator

6.1 檢測通路者的浏覽器和版本号

<html>
<body>
<script type="text/javascript">
var browser=navigator.appName
var b_version=navigator.appVersion
var 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.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
if ((browser=="Netscape"||browser=="Microsoft Internet Explorer") && (version>=4))
  {alert("您的浏覽器已經很棒了!")}
else
  {alert("您的浏覽器需要更新了!")}
}
</script>
</head>

<body οnlοad="detectBrowser()">
</body>

</html>
           

繼續閱讀