Note that because we don’t specify a source for the IFrame, we can modify its document content just like we do with window.open (same concept). Add the html code to the frame’s window’s document body. Note that using CSS’s display:none will not work because it won’t print. Set the width and heigh of the frame to 0 so it does not display in the page. Create an IFrame object and store its reference in the var frame. I have not tested for cross-browsers because I mainly work developing web applications for intranets, so this works well for internet explorer, but the logic of the code should work well for any browser (just adjust the browser specific lingo as needed). Var frame = document.createElement(“IFRAME”) į(htmlCode) The solution I found and has worked well so far: Use IFrames instead of windows. I assuming that because the window.open action gets triggered from the new thread that ajax creates, the browser does not know it came from a user driven event and I get the popup. For example, user clicks a button javascript gets some info from the server using ajax upon successful receipt, open a new window to print the results. What I have encountered first hand is when using ajax I get the popup blocker. Some research indicates that popups should not occur when the action happens direcly in user trigger event, such as onclick, but if it is embedded in another function that is called later, it may behave differently. I have used the window.open tip to print partial portions of HTML, but the one issue that I have encountered is that often I get popups that get blocked by the page, resulting in less than user friendly functionaly. If you have multiple print buttons, and each one prints selected area of a web page, then you need to pass id of the print area on each button click. Using these styles or css, we can style the text only for print. ![]() In the above example, I have added style and css file, you can use either one or both. You can hide some of the elements within your actual content by adding style elements or include css file in print window html Html+= document.getElementById(id).innerHTML – focus the window and call the “print()” function – create a print window and write html text you wanted to print If you want to print the whole page then ![]() Here, I am going to give code examples to above questions Do you want to print a part of the web page?ĭo you have multiple print buttons in a web page, which prints portion of the page?ĭo you want to exclude some elements in print of your page? (like images, ads)ĭo you want to print the display page differently? (changing font or colors of text)
0 Comments
Leave a Reply. |