怎么判断指定的网页是否存在? 如下代码:window.location.href="sims://1022";怎么判断指定的网页是否存在?谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script language="javascript"> var target = null; function createTarget(){ if(window.ActiveXObject){ target = new ActiveXObject("Microsoft.XMLHTTP") ; }else if(window.XMLHttpRequest){ target = new XMLHttpRequest(); } } function GetURL(url){ createTarget(); target.onreadystatechange = function(){ if(target.readyState==4){ if(target.status==200){ alert("页面存在"); }else { alert("页面不存在"); } } } target.open("GET",url,true); target.send(null); } </script> <input type="button" onclick="GetURL('http://www.baidu.com')" value="该页面存在"> <input type="button" onclick="GetURL('http://www.xxxxxx.com/xxxxx.html')" value="该页面不存在"></input> 这个只适合ie内核的浏览器,ff不支持 就是用的ajax 发送和接受请求吧!就是 ajax 兼容各大浏览器的问题了! String realPath = request.getSession().getServletContext().getRealPath(forwardStr); boolean exists = new File(realPath).exists(); if(exists){ request.getRequestDispatcher(forwardStr).forward(request, response); }else{ request.setAttribute("msg", "404,你懂的,未找到"+forwardStr); request.getRequestDispatcher(errorPage).forward(request, response); } 后台的,也许你用得到 我这样写怎么没响应? <input type="button" onclick="GetURL(sims://1022')" value="该页面存在"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>test</title><script src="jquery-1.4.4.js" type="text/javascript"></script><script type="text/javascript"> function testPageIsExist(){ $.ajax({ url: '1.html', type: 'post', success: function() { alert("此网页存在!"); }, error: function() { alert("错误,此网页不存在!"); } }); }</script></head><body><input type="button" id="btnOK" value="测试网页是否存在" onclick="testPageIsExist()" /></body></html>测试没有问题, ie, ff都可以的, 你自己附一个jquery的js文件就好了. 谢谢,测试网页没问题,但测试sims://1022没响应啊? 用window.location.href="sims://1022";连接有响应,只是不知怎么判断? 看看这里就知道了http://fss78.blog.163.com/blog/static/354265720104525149567/ 如何构造函数 点击运行 Javascript二级导航 请问如何动态改变循环语句 能不能在javascript中为session变量赋值,怎么实现 firefox下自动排边的问题 如何这样存储数据到access? javascript中如何判断一个控件是否存在? javascript比python难学吗 easyui 用tab标签用iframe不加载页面,用href可以加载,请大神帮忙找原因呀 这怎么做啊 js代码执行顺序 问题
var target = null;
function createTarget(){
if(window.ActiveXObject){
target = new ActiveXObject("Microsoft.XMLHTTP") ;
}else if(window.XMLHttpRequest){
target = new XMLHttpRequest();
}
}
function GetURL(url){
createTarget();
target.onreadystatechange = function(){
if(target.readyState==4){
if(target.status==200){
alert("页面存在");
}else {
alert("页面不存在");
}
}
}
target.open("GET",url,true);
target.send(null);
}
</script> <input type="button" onclick="GetURL('http://www.baidu.com')"
value="该页面存在">
<input type="button"
onclick="GetURL('http://www.xxxxxx.com/xxxxx.html')" value="该页面不存在"></input>
boolean exists = new File(realPath).exists();
if(exists){
request.getRequestDispatcher(forwardStr).forward(request, response);
}else{
request.setAttribute("msg", "404,你懂的,未找到"+forwardStr);
request.getRequestDispatcher(errorPage).forward(request, response);
} 后台的,也许你用得到
<input type="button" onclick="GetURL(sims://1022')"
value="该页面存在">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
<script src="jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
function testPageIsExist(){
$.ajax({
url: '1.html',
type: 'post',
success: function() {
alert("此网页存在!");
},
error: function() {
alert("错误,此网页不存在!");
}
});
}
</script>
</head>
<body>
<input type="button" id="btnOK" value="测试网页是否存在" onclick="testPageIsExist()" />
</body>
</html>测试没有问题, ie, ff都可以的, 你自己附一个jquery的js文件就好了.