假设website1.com/page_1.php的表单如下:
<form action="http://www.website1.com/action" method="post" id="myForm">
<input type="hidden" name="_token" value="sdfddgfg">
<input type="hidden" name="category_id" value="1">
<input type="submit" class="btn send" value="Send">
</form>
并且website2.com/page_2.php有这样的iframe:
<iframe src="http://www.website1.com/page_1.php"></iframe>
使用JQuery或JS,如何在访问myForm
时无需点击即可提交ID为website2.com/page_2.php?
的表单。
答案 0 :(得分:0)
您可以仅在iframe的HTML中执行类似的操作(您无需在“父”窗口中执行任何操作:
<html>
<head>
</head>
<body>
<form action="https://www.yoursite.com/" method="post" id="myForm">
<input type="hidden" name="_token" value="sdfddgfg">
<input type="hidden" name="category_id" value="1">
<input type="submit" class="btn send" value="Send">
</form>
<script>
(function() {
document.getElementById('myForm').submit()
})();
</script>
</body>
</html>