体验地址: 解决 ios 在h5使用alert和confirm出现url的问题
使用方法网络上也有很多,但是发现微信会有缓存,阻碍了数据的更新.
如果以前使用的时候出现了url,更新代码之后需要清除一下缓存,不然这个url是无法消失的,因为很可能你的数据更新了,微信内部浏览器并未更新你的数据,所以更新一下缓存数据吧
缓存这一块不知道是我频繁发布gitee的版本还是啥,后面更新的内容没有成功,所以我只能换了一个域名去看.
如果每次域名不一样的话,好像是不存在因为缓存页面无法更新问题的,这个方法也可以使用
代码主要是这样写的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=8"/>
<meta http-equiv="Expires" content="0"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Cache" content="no-cache"/>
<title>测试ios alert和comfirm功能</title>
<script src="./common.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>测试ios alert和comfirm功能 1122</h1>
</body>
</html>
<script type="text/javascript">
alert("alert:12345678")
confirm("confirm:12345")
</script>
common.js
window.alert = function(name) {
var iframe = document.createElement("IFRAME");
iframe.style.display = "none";
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
window.frames[0].window.alert(name);
iframe.parentNode.removeChild(iframe);
}
window.confirm = function(message) {
var iframe = document.createElement("IFRAME");
iframe.style.display = "none";
iframe.setAttribute("src", 'data:text/plain,');
document.documentElement.appendChild(iframe);
var alertFrame = window.frames[0];
var result = alertFrame.window.confirm(message);
iframe.parentNode.removeChild(iframe);
return result;
};