繁体   English   中英

未捕获的类型错误:window.reload 不是函数

[英]Uncaught TypeError: window.reload is not a function

我正在尝试从 div 中打印图像,代码运行正常,但是当打印对话框弹出时,我希望页面保持不变,而实际上它只显示图片,因为window.reload不起作用由于某些原因。 javascript 在控制台中告诉我"Uncaught TypeError: window.reload is not a function"但我不明白为什么。

  function printDiv(printableArea) {
    var printContents = document.getElementById("printableArea").innerHTML;
    var originalContents = document.body.innerHTML;
    document.body.innerHTML = printContents;
    window.print();
    window.close();
    window.reload();
  }

点击打印

<input type="button" onclick="printDiv('printableArea')" value="print a div!" />

您收到错误的原因是没有window.reload()方法。 您可能希望使用location.reload()来重新加载页面。

不确定是否有这样的功能,试试location.reload()

细节

使用location.reload(); window.location.reload(true);

https://webplatform.github.io/docs/apis/location/reload/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM