bonaca bonaca - 2 months ago 7
Javascript Question

how to change font family for new window

I want to print the content of a div and have the following solution:

w=window.open();
w.document.body.style.fontFamily = 'Arial';
w.document.write(tosend);
w.print();
w.close();


Everything works except
fontFamily
is not Arial but (I suppose) a default browser's serif font.

Answer

I guess you need an important property to set priority to your element

Try these answers

w.document.body.setAttribute('style', 'font-family:Arial !important');

else

w.document.body.style.cssText = 'font-family:Arial !important';

This below thing may not work in IE:

w.document.body.style.setProperty("font-family", "Arial", "important");

Or you can append an inline styling

w.document.body.appendChild(document.createTextNode('td.EvenRow a {font-family:Arial !important;}'))

If nothing works have a class with style property as important and use body.addClass="xx".

Finally have your java script at the end of the HTML which seems to be the best solution than all the above manipulatons.