如下代码,get提交的时候,通过window.location.replace(url)的方式,浏览器上的后退键还是灰色不可选的
但如果用创建form表单来post提交的话,就可以后退了,有什么办法让post提交也实现location.replace的效果吗??
最好是直接在下面的代码里补充,而不是在提交后的页面里对window.history进行操作
BTW,如果实在不行的话,在php里能够实现吗(用header??)<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" language="javascript">
function post(option) {
var ofm = document.createElement("FORM");
ofm.method = "POST";
ofm.action = option.url+"?timestamp="+(new Date().getTime());
ofm.style.display = "none";
for(var key in option.post) {
var tmp = document.createElement("INPUT");
tmp.type = "hidden";
tmp.name = key;
tmp.value = option.post[key];
ofm.appendChild(tmp);
}
document.body.appendChild(ofm);
ofm.submit();
} function get(url) {
window.location.replace(url+"×tamp="+(new Date().getTime()));
}
</script>
</head>
<body>
<input type="button" value="POST提交" onclick="post({url:'test5.php',post:{id:345,order:'name',esc:1,page:3}})" />
<input type="button" value="GET提交" onclick="get('test5.php?id=345&order=name&esc=1&page=3')" />
</body>
</html>
但如果用创建form表单来post提交的话,就可以后退了,有什么办法让post提交也实现location.replace的效果吗??
最好是直接在下面的代码里补充,而不是在提交后的页面里对window.history进行操作
BTW,如果实在不行的话,在php里能够实现吗(用header??)<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" language="javascript">
function post(option) {
var ofm = document.createElement("FORM");
ofm.method = "POST";
ofm.action = option.url+"?timestamp="+(new Date().getTime());
ofm.style.display = "none";
for(var key in option.post) {
var tmp = document.createElement("INPUT");
tmp.type = "hidden";
tmp.name = key;
tmp.value = option.post[key];
ofm.appendChild(tmp);
}
document.body.appendChild(ofm);
ofm.submit();
} function get(url) {
window.location.replace(url+"×tamp="+(new Date().getTime()));
}
</script>
</head>
<body>
<input type="button" value="POST提交" onclick="post({url:'test5.php',post:{id:345,order:'name',esc:1,page:3}})" />
<input type="button" value="GET提交" onclick="get('test5.php?id=345&order=name&esc=1&page=3')" />
</body>
</html>
<iframe style="display:none" name=t></iframe>ofm.target="t"
IE8+ff测试通过
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" language="javascript">
function post() {
var ofm = document.createElement("FORM");
document.body.appendChild(ofm)
ofm.method = "POST";
ofm.action = "http://dotnet.aspx.cc"
ofm.style.display = "none";
ofm.target = "t"
ofm.submit();
}
</script></head>
<body>
<iframe name="t"></iframe>
<input type="button" value="POST提交" onclick="post()" />
</body>
</html>