我有一个HTML页面,其中包含隐藏的表单参数,我想在单击传递相同参数的HTML页面时重定向到另一个URL。我目前无法使用ID和密码重定向。
<html>
<body>
<script language="javascript">
function runReport()
{
document.mstr.submit();
}
</script>
<form name = "mstr" action = "www.xyz.com" method = "post">
<input type="hidden" name="uid" value="xyz" />
<input type="hidden" name="pwd" value="xyz" />
</form>
</body>
</html>
答案 0 :(得分:0)
您可以通过几种不同的方式重定向。一个是window.location
:
window.location = 'newPage.php';
您可以将$_GET[]
个变量附加到网址的末尾。
如果您想发布变量,则需要使用表单:
<form id="hiddenForm" action="newPage.php" method="post">
<input type="hidden" name="uid" value="..."/>
<input type="hidden" name="pwd" value="..."/>
</form>
使用Javascript:
document.getElementById("hiddenForm").submit();
然后在newPage.php上,您可以使用$_POST[]
访问变量:
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
答案 1 :(得分:0)
使用jquery监听器进行双击(dblclick),然后可以绑定到该监听器并在文档中双击任何人时提交。这会将表单中的数据发布到表单的操作URL。
<!DOCTYPE html>
<html>
<head>
<title>XYZ</title>
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<script>
$(function() {
$(document).on('dblclick', function() {
$('form[name="mstr"]').submit();
});
});
</script>
<form name="mstr" action="http://www.xyz.com" method="post">
<input type="hidden" name="uid" value="xyz" />
<input type="hidden" name="pwd" value="xyz" />
</form>
</body>
</html>
如果您的操作使用的是另一个网址,那么您现在所使用的网址则需要http://
或https://
您还可以使用//www.your-domain.com
,这将模仿当前网站。因此,如果您目前位于http
,则会使用https