【发布时间】:2015-05-24 06:16:18
【问题描述】:
我有一个如下页面:
<html>
<head></head>
<body>
<form name="myform" action="http://www.example.com/page" method="post">
<input type="hidden" name="param1" value="1">
<input type="hidden" name="param2" value="2">
<input type="hidden" name="param3" value="3">
<input type="submit" value="Click Here If Not Redirect">
</form>
<script language="JavaScript">
document.myform.submit();
</script>
</body>
</html>
我想要一个 JavaScript 代码(没有 jQuery 什么的,轻量级在我的项目中非常重要)来做上面的事情(使用 POST 参数自动重定向页面)。我不希望用户看到重定向页面。例如这样的:
<html>
<head>
<meta http-equiv="refresh" content="0; url=http://www.example.com/page">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
</head>
<body>
</body>
</html>
当然还有 POST 参数。
我的问题有什么解决办法吗?
【问题讨论】:
-
如果我正确理解了您的问题,那么您可以使用 window.redirect 并将参数作为查询字符串传递
-
感谢您的评论。有没有办法发布参数?我上面的第一个代码是 POSTing 参数,但用户看到页面大约 5 到 10 秒。在第二个代码中,我无法发布参数,但用户一看到页面就会重定向(不到一秒)。提前谢谢你。
标签: javascript redirect post parameters