Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
159
rated 0 times [  162] [ 3]  / answers: 1 / hits: 21180  / 10 Years ago, tue, may 13, 2014, 12:00:00

I am having an issue with print on Safari. My System is Windows 7, and this function works fine in all other browsers except Safari. Here is the situation:



window.onload = function(){
console.log('before print');
window.print();
}


It won't output the log in console panel, but the print page will appear first, after i choose cancel in print page, the log will be output.



Does any body came up with this issue? Any help will be appreciated.



Updated



Here is the situation i have:
We need to print a page whose content can be changed by user by checking and unchecking check box, and only the content part of this page should be printed, so we create a new page that only contains the content for printing. In this page, we need to hide the unnecessary content that is not selected by user, so we need to do some DOM operation before window.print() get called. The console.log() is just an example code for observing. I tried to add an <div id='test'>Test HTML</div> in test HTML and add



var test = document.getElementById('test');
test.style.background = 'yellow';


before window.print();, it shows the same result in my Safari browser, the 'Test HTML' will not turn to yellow until i click cancel button in print panel, so it's not just the console.log issue.



Updated



I am using Safari 5.1.7(7534.57.2) on Windows 7


More From » printing

 Answers
12

After several times trying, below code works, but i don't know the reason, can anybody explain? Or this is a Safari Bug?



window.onload = function() {
$('body').html('After change');
setTimeout(window.print, 1000);
};

[#71047] Sunday, May 11, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;