【问题标题】:Execute function after clicking a button in a new window在新窗口中单击按钮后执行功能
【发布时间】:2019-03-17 03:23:39
【问题描述】:

我在网站上有“打开窗口”按钮,它打开一个新窗口,其中还有其他按钮。如果用户关闭此窗口,则不会发生任何事情。但是如果他按下这个按钮 - 窗口会关闭,并在网站本身上执行一个功能。

希望你能理解我,谢谢!

<input type="button" value="New window" onclick="createWindow();"/>
<a id="done"></a>
<script>
function createWindow() {
  var win = window.open('', 'popup', 'status=no,toolbar=no,location=no,directories=no,resisable=no,srollbars=yes,width=1050,height=600');
  content = '<input type="button" value="call Function" onclick="done();"/>';
  content += 'this button should call done() function';
  win.document.write(content);
}

function done() {
    document.getElementById('done').text = 'done!';
}
</script>

http://jsfiddle.net/5qp0v2x8/4/

【问题讨论】:

  • 请分享一些尝试过的代码
  • 你能再清楚一点。你到底想完成什么?
  • @boussadjrabrahim 当然! jsfiddle.net/5qp0v2x8/4
  • @johnnylak 试图调用 done() 函数:jsfiddle.net/5qp0v2x8/4
  • 函数done()应该存在于new窗口中。

标签: javascript jquery


【解决方案1】:

你需要做的就是改变你的onclick监听器:

onclick="window.opener.done();"

Learn more about window.opener

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 2018-08-21
    • 2015-09-09
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    相关资源
    最近更新 更多