怎么判断指定的网页是否存在? 如下代码: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/ js判断文本框输入的是不是数字 JS图片上传浏览 400元求Javascript/Ajax脚本:客户端浏览器编辑多张图片,并可对每张图进行旋转1~360度、裁剪选中部分等操作 使用过dtree的大哥们帮我看下问题 类似excel合并单元格的js 请教大侠! 我已写的js文件,现在要采用vb的ActiveX控件对这部分js进行封装.该如何实现 各位GGJJ,小弟想问一下,在web页面上,怎么将鼠标的右键屏蔽掉???? 紧急求助——关于下拉菜单的问题 怎样做一个将剪贴板内容粘贴到textarea中的按钮? Eclipse 搭建Node.js环境问题 这怎么做啊 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文件就好了.