【问题标题】:JavaScript open popup window and simulate mouse click on specific positionJavaScript 打开弹出窗口并模拟鼠标点击特定位置
【发布时间】:2016-09-25 04:20:52
【问题描述】:

我需要打开弹出窗口“Page1.html”,然后自动单击“VOTE”按钮,然后该页面被重定向到“Page2.html”。

我知道以下打开弹出窗口“Page1.html”的代码

<script type="text/javascript">
function makeNewWindow()
{
winchlildren = window.open("./page1.html","winchlildren","height=600,width=85")
}
</script>

我有按钮所在的表单。

<!DOCTYPE html>
<html>
<head></head>
<body>
<div class="votelog_info">
    <div class="votelog_nav">
        <div class="vote_nav is_voteing">
            <form method="post">
            <input type="hidden" name="form_pass" value="form_pass_qk9telqr2G4hU" />
            <input type="hidden" name="id" value="norrcon" />
            <button type="submit" class="vote for" name="submit">Vote</button></form>
        </div>
    </div>
</div>
</body>
</html>

按下此按钮后,我希望将页面重定向到“Page2.html”
我希望这个过程在后台和全屏尺寸下完成。
谢谢!
埃德加。

【问题讨论】:

  • the vert page - 什么是垂直页面?
  • I want this process to be done in the background and full-screen size - 你似乎对 SO 是什么感到困惑 - 它不是代码编写服务
  • 如果所有有问题的页面都是你的页面(我假设它们被赋予了page1.html的路径)你为什么还需要第二个窗口?你不能只向那个 URL 发出一个 ajax 请求来提交投票吗?
  • @JaromandaX 页面OK
  • @nnnnnn 我不懂 JS

标签: javascript jquery popup window popupwindow


【解决方案1】:

你已经把这个问题提交给了 Jquery,你可以使用 JS 来完成它:

<script type="text/javascript">
    function makeNewWindow() {
        winchlildren = window.open("./page1.html","winchlildren","height=600,width=85");

        $('.is_voteing input[name="submit"]').click();
    }
    $(".is_voteing input[name="submit"]').click(function(){
        // do voting functionality when button is clicked
        // AJAX is preffered, if process to be done in the background
        . . .
        //Redirect completely to page2.html (full screen size, as you reffered)
        window.location = "./page2.html";
    });
</script>

然后在页面上的任何事件上调用makeNewWindow()

【讨论】:

  • This: $('.is_voteing input[name="submit"]').click(); 将针对 current 文档运行,而不是针对在新窗口中打开的 page1.html。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-05
  • 2011-08-05
  • 1970-01-01
相关资源
最近更新 更多