Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:05:40+00:00 2026-05-31T15:05:40+00:00

I wish to print a document by passing custom html code. The non-working code

  • 0

I wish to print a document by passing custom html code.

The non-working code I have written :

function Clickheretoprint()
{
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=780, height=780, left=100, top=25"; 
  var content_vlue = document.getElementById("result_tbl").innerHTML; 

  var docprint=window.open("","",disp_setting); 
  docprint.document.open(); 
  docprint.document.write('<html><head><title>Ashley Mattresses</title>'); 
  docprint.document.write('</head><body onLoad="self.print()"><center>');          
  docprint.document.write('<TABLE width="100%" cellpadding=10 align=center  valign="top"><TR valign="top"><TD width = "33%" valign="top">col1</TD><TD width = "33%" valign="top">col2</TD><TD width = "33%" valign="top">col3</TD></TR></TABLE>');     
  docprint.document.write('</center></body></html>'); 
  docprint.document.close(); 
  docprint.focus(); 
  docprint.close();
}

This is the method I called on href of an anchor tag, but the not getting the work done:

<a href="javascript:Clickheretoprint()">

I am a beginner to JavaScript/jQuery coding.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:05:41+00:00Added an answer on May 31, 2026 at 3:05 pm

    You are on the right track. Assuming result_tbl is the ID of element you like to print as-is, first wrap the element with a <div> tag e.g.:

    <div>
        <table id="result_tbl">
            .....
        </table>
    </div>
    

    Then have such code:

    var docprint=window.open("about:blank", "_blank", disp_setting); 
    var oTable = document.getElementById("result_tbl");
    docprint.document.open(); 
    docprint.document.write('<html><head><title>Ashley Mattresses</title>'); 
    docprint.document.write('</head><body><center>');
    docprint.document.write(oTable.parentNode.innerHTML);
    docprint.document.write('</center></body></html>'); 
    docprint.document.close(); 
    docprint.print();
    docprint.close();
    

    Live test case.

    Working fine for me under Chrome 18:

    print is working

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to print a chart. I do as follow : var printJob :
I wish to let client to have a pretty print page from a web
I wish to print a Stack<Integer> object as nicely as the Eclipse debugger does
I wish to print out double as the following rules : 1) No scietific
I have subclassed java.awt.Frame and have overridden the paint() method as I wish to
I have an onclick function which performs several tasks. In another JavaScript function I
I have a form on which I have a number of textboxes. I wish
code a = 한글 #korean language a_list = [] a_list.append({'key': a}) print a_list result
I wish there is an efficient way to print out my format. As I
I want to print a specific NSView. When I do this, I wish to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.