views:

66

answers:

3

In the below code,

in a.html there is this code as,

         <div id="tableview"></div>//Data loaded dynamically

         <input type="button" id="printbtn" onclick="print()"/>             
         <script>
         function print()
         {
            var data=$('#tableview').html();
            dataobj.print();
          }

In b.html

I need to print a.html without opening it ,But without opening it how will the data in the div get generated and how to print only this data from b.html

Thanks..

A: 
  1. Make an Ajax call to b.htm

  2. Get the content of the div you want.

  3. Return the data into a hidden div in a.htm

  4. Make a print style sheet which everything is hidden in that view and only the previously hidden div is visible.

  5. call your print function

XGreen
A: 

I think you can make an ajax request to b.html to get the content and then print it.

function contentprint()
{
$.ajax({
           url : "b.html",
           success : function (data) {
           var data1=data;
           data1.print();
}
});
}

HTH

Raja
yes that is correct.just the url bit should be "b.htm#mycontent"
XGreen
+1  A: 

Update: This answer is assuming that no postback should occur based on your question. (No Ajax)

If you only have one print view per a page you can apply a media=print filter on to the page. Load both views initially and only show the screen view to the screen.

<Style href="print.css" media="print" />

You can set all the screen display to hidden and show the prinatble view:

 * {
    visibility: hidden;
  }

  #tableview * {
    visibility: visible;
  }
Glennular
IMO, this is the right way to do it. There is no reason to fetch the page again; this is precisely what print stylesheets are for!
pkaeding