一、探测对象
在编写脚本时,可能希望检查浏览器是否有能力理解你要使用的对象。进行这种检查的方法叫 对象探测。
例如:
window.onload=initAll;
function initAll()
{
if (document.getElementById) {
alert("123,yes");
} else {
alert("Sorry,your browser doesn't support this script!!");
}
}
例如:
window.onload = initAll;
function initAll() {
document.getElementById("redirect").onclick = initRedirect;
}
function initRedirect() {
window.location = "jswelcome.html";
return false; //表示停止对用户单击事件的处理,这样就不会加载href指向的页面
}
本文介绍了如何使用JavaScript进行对象探测以确保浏览器支持特定功能,并展示了如何通过修改窗口位置属性实现页面重定向。
1万+

被折叠的 条评论
为什么被折叠?



