Click here to Skip to main content
13,349,568 members (49,454 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Dear Friends,
I found this JavaScript function on a Example of my friend.
Can someone plz explain me this function in details ?

function callPrint(elementId) {
                var prtContent = document.getElementById(elementId);
                var WinPrint ='', '', 'left=0,top=0,width=1000,height=600,toolbar=2,scrollbars=2,status=0');
                var docColor = "Black";
                var strInnerHTML = prtContent.innerHTML;
                var strModifiedInnerHTMl = strInnerHTML.replace(/white/g, docColor);

I need Explanation from 3rd line Onward.

Thanks For Helping.
Posted 3-Oct-12 7:05am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

var docColor = "Black"

Create a variable named docColor and set its value to the string "Black"
var strInnerHTML = prtContent.innerHTML;

Create a variable named strInnerHTML and set its value to the innerHTML value of the prtContent page element.
var strModifiedInnerHTMl = strInnerHTML.replace(/white/g, docColor);

Create a variable named strModifiedInnerHTML and set its value to a modified copy of strInnerHTML where any instances of "white" have been replaced by the current value of docColor(Which is currently "Black"). This is being done with a regular expression /white/ with a g switch indicating that it will update all instances that it finds.

Writes the strModifiedInnerHTML string to a WinPrint document object.

Closes the WinPrint document

Gives the WinPrint object focus

Sends the Winprint object to the printer

Closes/Finished the WinPrint object. More than likely this call is required to clean up resources that the WinPrint object required to perform its actions.
Gittu Dash 3-Oct-12 14:40pm
Bro, just explain me abt "/white/g" in "strInnerHTML.replace(/white/g, docColor);".
This was my main doubt.
Also why "WinPrint.document.close();" is used ?

Plz Explain Me.
Marcus Kramer 3-Oct-12 15:35pm
See Updated Answer.
Gittu Dash 3-Oct-12 16:00pm
So Can We Mention Anything else in Place of 'g'
Means where can I find options use like this ?

Also plz Tell me why it used "WinPrint.document.close();"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100