jquery - Javascript printing on Chrome and IE -
i have code in webpage generates table should printed on page table on it.
this used work fine in chrome, until recently, works in microsoft edge (which fine if computers in our warehouse on windows 10, not, , cannot) - need desperately work in chrome, or last resort, internet explorer.
here code generates tables:
<div id="printthis" style="display:none;width:95%;"> <div style="width:95%;border:2px groove black;display:none;"> <!-- latest compiled , minified css --> <link rel="stylesheet" href="../css/bootstrap.min.css"> <!-- optional theme --> <link rel="stylesheet" href="../css/theme.css"> <table> <center> <p><? echo $parseday . " - " . $leads[$_get["line"]] . "'s line"; ?></p> </center> </table> <table class="table table-bordered" style="font-size:12px;width:95%;"> <tr> <thead> <th width="125px">name</th> <th width="50px">job</th> <th>notes</th> <th align="right" width="50px">emergency</th> </thead> </tr> <? while($row = mysqli_fetch_array($check)) { $explodeat = explode("|", $row['at']); $explodenotes = explode("|", $row['notes']); if((((strcmp($parseday1, 'mon') == 0) && (strcmp($explodeat['0'], 'absent') == 0)) || ((strcmp($parseday1, 'tue') == 0) && (strcmp($explodeat['1'], 'absent') == 0)) || ((strcmp($parseday1, 'wed') == 0) && (strcmp($explodeat['2'], 'absent') == 0)) || ((strcmp($parseday1, 'thu') == 0) && (strcmp($explodeat['3'], 'absent') == 0)) || ((strcmp($parseday1, 'fri') == 0) && (strcmp($explodeat['4'], 'absent') == 0))) || (((strcmp($parseday1, 'mon') == 0) && (strcmp($explodeat['0'], '') == 0)) || ((strcmp($parseday1, 'tue') == 0) && (strcmp($explodeat['1'], '') == 0)) || ((strcmp($parseday1, 'wed') == 0) && (strcmp($explodeat['2'], '') == 0)) || ((strcmp($parseday1, 'thu') == 0) && (strcmp($explodeat['3'], '') == 0)) || ((strcmp($parseday1, 'fri') == 0) && (strcmp($explodeat['4'], '') == 0)))) { //if absent or unmarked, don't include. } else { //if else, include. echo '<tr>'; echo '<th width="125px">'.$row['name'].'</th>'; echo '<th>'.$row['job'].'</th>'; if((strcmp($parseday1, 'sat') == 0) || (strcmp($parseday1, 'sun') == 0)) { echo '<th>today not accounted for.</th>'; } else { if(strcmp($parseday1, 'mon') == 0) { echo '<th>'.$explodenotes['0'].'</th>'; } else if(strcmp($parseday1, 'tue') == 0) { echo '<th>'.$explodenotes['1'].'</th>'; } else if(strcmp($parseday1, 'wed') == 0) { echo '<th>'.$explodenotes['2'].'</th>'; } else if(strcmp($parseday1, 'thu') == 0) { echo '<th>'.$explodenotes['3'].'</th>'; } else if(strcmp($parseday1, 'fri') == 0) { echo '<th>'.$explodenotes['4'].'</th>'; } } echo '<th><center><div style="width:15px;height:15px;border:1px solid black;border-radius:2px;"></div></center></th>'; echo '</tr>'; } } ?> </table> </div> </div>
which works way meant to, generates fine microsoft edge, , if display divs generate fine on page. idea is hidden on page when button pressed opens div in own window , prints that.
here javascript (which believe problem lies, wrong, i'm not great javascript.)
<script type="text/javascript"> function printthis() { var w = window.open('', '', 'width=800,height=600,resizeable,scrollbars'); w.document.write($("#printthis").html()); w.document.close(); // needed chrome , safari javascript:w.print(); w.close(); return false; } </script>
i not understand why works fine in microsoft edge , not in chrome or ie.
if other information needed me resolve this, more happy supply it.
which want.
now, in chrome gets little weird. @ first dialogue:
but if play around destination, , change way file saves, diaogue:
it looks css error. have display:none set twice.
try changing first 2 lines:
<div id="printthis" style="display:none;width:95%;"> <div style="border:2px groove black;">
...
if still not working, can use bootstrap css imported.
- remove javascript altogether if like. (then can use browser's print command. no new window needed).
- move
<link rel="stylesheet" href="../css/bootstrap.min.css">
<head></head>
. stylesheets supposed go inside<head>
. - you apply class="visible-print" items want show when printing.
- you apply class="hidden-print" items want hide when printing.
something this:
<div class="hidden-print"> stuff don't want print </div> <div id="printthis" class="visible-print"> <div style="width:95%;border:2px groove black; margin:0 auto;"> ...your table stuff
Comments
Post a Comment