c# - site freezes after closing the print window -


i using jquery.printelement.js print. when click on print button print window opens print , cancel button. if print document or cancel print window every thing works fine, if close window close button in title bar [x] stops working after dispose of print window on chrome version 35.

/// <reference path="http://code.jquery.com/jquery-1.4.1-vsdoc.js" /> /* * print element plugin 1.2 * * copyright (c) 2010 erik zaadi * * inspired printarea (http://plugins.jquery.com/project/printarea) , * http://stackoverflow.com/questions/472951/how-do-i-print-an-iframe-from-javascript-in-safari-chrome * *  home page : http://projects.erikzaadi/jqueryplugins/jquery.printelement  *  issues (bug reporting) : http://github.com/erikzaadi/jqueryplugins/issues/labels/printelement *  jquery plugin page : http://plugins.jquery.com/project/printelement  *   *  david b (http://github.com/ungenio) , icgjohn (http://www.blogger.com/profile/11881116857076484100) *  great contributions! *  * dual licensed under mit , gpl licenses: *   http://www.opensource.org/licenses/mit-license.php *   http://www.gnu.org/licenses/gpl.html *    *   note, iframe printing not supported in opera , chrome 3.0, popup window shown instead */ ; (function (window, undefined) {     var document = window["document"];     var $ = window["jquery"];     $.fn["printelement"] = function (options) {         var mainoptions = $.extend({}, $.fn["printelement"]["defaults"], options);         //iframe mode not supported opera , chrome 3.0 (it prints entire page).         //http://www.google.com/support/forum/p/webmasters/thread?tid=2cb0f08dce8821c3&hl=en         if (mainoptions["printmode"] == 'iframe') {             if ($.browser.opera || (/chrome/.test(navigator.useragent.tolowercase())))                 mainoptions["printmode"] = 'popup';         }         //remove printed iframe if exists         $("[id^='printelement_']").remove();          return this.each(function () {             //support metadata plug-in if available             var opts = $.meta ? $.extend({}, mainoptions, $(this).data()) : mainoptions;             _printelement($(this), opts);         });     };     $.fn["printelement"]["defaults"] = {         "printmode": 'iframe', //usage : iframe / popup         "pagetitle": '', //print page title         "overrideelementcss": null,         /* can 1 of following 3 options:         * 1 : boolean (pass true stripping css linked)         * 2 : array of $.fn.printelement.csselement (s)         * 3 : array of strings paths alternate css files (optimized print)         */         "printbodyoptions": {             "styletoadd": 'padding:10px;margin:10px;', //style attributes add body of print document             "classnametoadd": '' //css class add body of print document         },         "leaveopen": false, // in case of popup, leave print page open or not         "iframeelementoptions": {             "styletoadd": 'border:none;position:absolute;width:0px;height:0px;bottom:0px;left:0px;', //style attributes add iframe element             "classnametoadd": '' //css class add iframe element         }     };     $.fn["printelement"]["csselement"] = {         "href": '',         "media": ''     };     function _printelement(element, opts) {         //create markup printed         var html = _getmarkup(element, opts);          var popuporiframe = null;         var documenttowriteto = null;         if (opts["printmode"].tolowercase() == 'popup') {             popuporiframe = window.open('about:blank', 'printelementwindow', 'width=650,height=440,scrollbars=yes');             documenttowriteto = popuporiframe.document;         }         else {             //the random id overcome safari bug http://www.cjboco.com.sharedcopy.com/post.cfm/442dc92cd1c0ca10a5c35210b8166882.html             var printelementid = "printelement_" + (math.round(math.random() * 99999)).tostring();             //native creation of element faster..             var iframe = document.createelement('iframe');             $(iframe).attr({                 style: opts["iframeelementoptions"]["styletoadd"],                 id: printelementid,                 classname: opts["iframeelementoptions"]["classnametoadd"],                 frameborder: 0,                 scrolling: 'no',                 src: 'about:blank'             });             document.body.appendchild(iframe);             documenttowriteto = (iframe.contentwindow || iframe.contentdocument);             if (documenttowriteto.document)                 documenttowriteto = documenttowriteto.document;             iframe = document.frames ? document.frames[printelementid] : document.getelementbyid(printelementid);             popuporiframe = iframe.contentwindow || iframe;         }         focus();         documenttowriteto.open();         documenttowriteto.write(html);         documenttowriteto.close();         _callprint(popuporiframe);     };      function _callprint(element) {         if (element && element["printpage"])             element["printpage"]();         else             settimeout(function () {                 _callprint(element);             }, 50);     }      function _getelementhtmlincludingformelements(element) {         var $element = $(element);         //radiobuttons , checkboxes         $(":checked", $element).each(function () {             this.setattribute('checked', 'checked');         });         //simple text inputs         $("input[type='text']", $element).each(function () {             this.setattribute('value', $(this).val());         });         $("select", $element).each(function () {             var $select = $(this);             $("option", $select).each(function () {                 if ($select.val() == $(this).val())                     this.setattribute('selected', 'selected');             });         });         $("textarea", $element).each(function () {             //thanks http://blog.ekini.net/2009/02/24/jquery-getting-the-latest-textvalue-inside-a-textarea/             var value = $(this).attr('value');             //fix issue 7 (http://plugins.jquery.com/node/13503 , http://github.com/erikzaadi/jqueryplugins/issues#issue/7)             if ($.browser.mozilla && this.firstchild)                 this.firstchild.textcontent = value;             else                 this.innerhtml = value;         });         //http://dbj.org/dbj/?p=91         var elementhtml = $('<div></div>').append($element.clone()).html();         return elementhtml;     }      function _getbasehref() {         var port = (window.location.port) ? ':' + window.location.port : '';         return window.location.protocol + '//' + window.location.hostname + port + window.location.pathname;     }      function _getmarkup(element, opts) {         var $element = $(element);         var elementhtml = _getelementhtmlincludingformelements(element);          var html = new array();         html.push('<html><head><title>' + opts["pagetitle"] + '</title>');         if (opts["overrideelementcss"]) {             if (opts["overrideelementcss"].length > 0) {                 (var x = 0; x < opts["overrideelementcss"].length; x++) {                     var current = opts["overrideelementcss"][x];                     if (typeof (current) == 'string')                         html.push('<link type="text/css" rel="stylesheet" href="' + current + '" >');                     else                         html.push('<link type="text/css" rel="stylesheet" href="' + current["href"] + '" media="' + current["media"] + '" >');                 }             }         }         else {             $("link", document).filter(function () {                 return $(this).attr("rel").tolowercase() == "stylesheet";             }).each(function () {                 html.push('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" media="' + $(this).attr('media') + '" >');             });         }         //ensure relative links work         html.push('<base href="' + _getbasehref() + '" />');         html.push('</head><body style="' + opts["printbodyoptions"]["styletoadd"] + '" class="' + opts["printbodyoptions"]["classnametoadd"] + '">');         html.push('<div class="' + $element.attr('class') + '">' + elementhtml + '</div>');         html.push('<script type="text/javascript">function printpage(){focus();print();' + ((!$.browser.opera && !opts["leaveopen"] && opts["printmode"].tolowercase() == 'popup') ? 'close();' : '') + '}</script>');         html.push('</body></html>');          return html.join('');     }; })(window); 

is there way identify close event , end peacefully or not show [x] option @ right top corner?

hi struggled past 3 days, , came conclusion of following:

these lines:

if (mainoptions["printmode"] == 'iframe') {   if ($.browser.opera || (/chrome/.test(navigator.useragent.tolowercase())))     mainoptions["printmode"] = 'popup'; } 

are obsoletes , seems cause issues in chrome, happens time when plugin created, chrome , opera have issues when printing iframe content.

as of today that's not longer issue (and since opera uses webkit chrome, must assume happens work on opera well).

so removes lines , notice print dialog not have blank window anymore, hence should not have problem.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -