Skip to content

Commit 8b1d33b

Browse files
authored
Merge pull request #152 from Junior125306/Junior125306-patch-1
修复某些特定情况下 onload 函数重复调用 导致重复弹出浏览器预览打印弹窗的bug
2 parents 5d7b6e3 + c07cf11 commit 8b1d33b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/hiprint/plugins/jquery.hiwprint.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(function ($) {
22
$.fn.hiwprint = function (options) {
3+
var hasLoaded = false;
34
var usedFrame = document.getElementById('hiwprint_iframe');
45
if (usedFrame) usedFrame.parentNode.removeChild(usedFrame);
56
var opt = $.extend({}, $.fn.hiwprint.defaults, options);
@@ -23,6 +24,8 @@
2324
$iframe[0].srcdoc = '<!DOCTYPE html><html><head><title></title><meta charset="UTF-8">' + css + '</head><body></body></html>';
2425

2526
$iframe[0].onload = function () {
27+
if (hasLoaded) return;
28+
hasLoaded = true;
2629
var printDocument = $iframe[0].contentWindow || $iframe[0].contentDocument;
2730
if (printDocument.document) printDocument = printDocument.document;
2831
if (!$iframe.attr('srcdoc')) {

0 commit comments

Comments
 (0)