English 中文(简体)
Chrome窗. print窗.close()导致印刷版审查失败。 解决办法?
原标题:Chrome window.print() window.close() results in print preview failed . Solution?

I have a print page that opens in a new tab or window. The resulting page opens a print dialog. After the user makes a selection on the print dialog, the page then closes the tab/window.

window.print();
window.close();

This used to work great in the major browsers, but one of the latest versions of Chrome breaks this (i.e. 14.0.835.202).

I receive the following message from what I guess is the chrome print plugin: "Print preview failed".

是否有办法在印刷后关闭 Chrome-tab/window?

最佳回答
问题回答

我刚刚找到了适合我的解决办法。 我从秘鲁的答复开始,但不想在这一解决办法中使用 j。

window.onload = function () {
  window.print();
  setTimeout(function(){window.close();}, 1);
}

理由 Chrome原开始时间,直到印刷方言关闭。

Similar issue, I had.

FYI FOR ALL AS OF VER 17+ I was using the jquery plugin, printElement and had found a way to edit it so I could close the window, even in chrome ... then they updated to this new print thing! I have a solution yet again.

Previous

Chrome used to open a seperate window containing just the element i wanted 
printed and its relative css.  That window then spawned the .print command 
which opened another window containing print preview. By adding a simple 50 
millisecond timeout i was able to close the previous window without hurting 
the print preview.

<>新问题>

Chrome no longer opens a new window for their print preview. Instead it 
opens a "dialog with overlay" in the current page to be printed (aka, our 
new blank page containing just the element for print). Thus, when my timer 
kicked in, it wouldn t close the page immediately, but as soon as the dialog 
code closed.  The problem was, it closed so fast, the print command never 
made it to its service and thus nothing was printed to pdf 
(what our clinic uses).

<>新解决方案>

我知道增加时间无助于事,因为时间会接近尾声,而且仍然可以停止印刷。 相反,我与最近的支架一道,在新网页的头盔上架设一个文字链接,然后在纸面上加上。 On! 并对...... 它是“善!”

在夏天,如果你重新使用空白页,在剪辑中印刷,并且需要在你的内容/面印后关闭网页,那么就只是在该网页上添加一个贴近窗户的 h子上。 然后,如果你选择了一种印刷方法并打上了印刷,就会印刷和关闭方言,使你失去窗户。 简单地把你们的摩擦推向时代和世界法律学会! ONE光窗是:

以上所有解决办法都没有解决我的问题,因为这项法典解决了我的问题。

setTimeout(function () {
        mywindow.print();
        mywindow.close();
    }, 1000); 

将这一文字添加到你的播种印刷窗口中

<script src="/assets/print_window_close.js" type="text/javascript"></script>

印刷内容

jQuery(document).ready(function() {

    setTimeout(function() {
        window.close();
    }, 1);

});

基本上只有在文件重点明确时,才需要时间,而超时印刷方言被关闭。 因此,这完全是你想要的。

对我来说,我没有找到解决办法,这样就产生了解决办法。

什么是使用一套固定案文箱制造的无形文本箱,而侧重于它。 窗户后每50个点间打印。 还将焦点活动与文字箱挂钩,一旦它打开窗户。 测试是在“ Chrome”、“ Firefox”和“因特网探索者”。

window.print();
setInterval(function () {
  document.getElementById("focustext").focus();
}, 50);
document.getElementById("focustext").onfocus = function () { window.close(); }
#focustext {
  border: none;
  height: 0px;
  width: 0px;
}
<input id="focustext" type="text" />

我目前的黑板。 基本上,就在窗户之后,即把烟花、点击和主要压力捆绑起来,触发我想要采取的行动(窗口.close();或窗口. 所在地。 只要用户nothing,确保行动不会发生。 但它运作良好。 (居民,至少可以住到ug虫得到纠正为止)

/* 
// alternative to window.print() for dedicated print windows (had issue with <body onload=window.print()...
// not used anymore.
$( <a id="aprint" href="#" onclick="return window.print()" class="invisible"></a> ).appendTo( body );
$( #aprint ).trigger( click );
*/
$( body, select, input, textarea, button, submit, form ).prop( disabled , true);
window.print();
setTimeout(function() {
    $( body ).bind( mousemove click keypress , function () {
        window.location.href=home;                      
    });
}, 200);    

我解决这一问题:

window.print();
if(/Chrome/.test(navigator.userAgent)){
  $(window).focus(function(){
    window.location =  /print-thank-you ;
  });
} else {
  window.location =  /print-thank-you ;
}

EDIT: 印刷 Chrome版;17项作品,仅像IE/FF,这样就能够确保你对此负责。

在经过下午的研究和回答之后,我找到了一种解决办法,目前我使用的版本是:

IE : 9.0.8...

FireFox: 15.01

页: 1

Safari: 5.1.7

在准备在印刷特定网页上展示html时,包括检查

if (oWindow == null || oWindow.closed || typeof(oWindow) == "undefined")

然后通知用户,以便临时居住。 为了让你的网页开放,显示印刷方言,并在打印方言后关闭,把这一功能添加到窗户的上载功能上:

function PrintPage()
{
    self.print();
    self.onmouseover = (function() { window.close(); }
}

这样做的原因是,从根本上说,我们仍在处理物体和事件。 浏览器在某些方面可能有所不同,但它们都有共同的立足点。 希望在窗口收益集中时总是会发生简单的转播活动,因此,希望这一守则不会失去其相关性。

它对我的工作课以罚款......

var newWin = window.open(  ,   );
//htmlPage is your html content 
setTimeout(newWin.document.write(htmlPage),1000);
// newWin.document.body.innerHTML = htmlPage;
newWin.document.close();
newWin.focus();
setTimeout(newWin.print(), 10000);
newWin.document.close();
newWin.close();
return false;

Tested today works for IE, FF, Chrome (including preview fix for chrome)

    setTimeout(function () { window.print(); }, 500);
    window.onfocus = function () { setTimeout(function () { window.close(); }, 500); }




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签