Print web page ?

R

RAYMOND PISTEY

Hello on my site this is what is happenning

Part 1 - This is what works and prints me output I like from <print> link in
body section

<head>
<script type="text/javascript">
function ClickHereToPrint(){
try{
var oIframe = document.getElementById('ifrmPrint');
var oContent = document.getElementById('divToPrint').innerHTML;
var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
oDoc.write("<html><head><title>title</title>");
oDoc.write("</head><body onload='this.focus(); this.print();'>");
oDoc.write(oContent + "</body></html>");
oDoc.close();
}
catch(e){
self.print();
}
}
</script>
</head>


<body>

<a onclick="ClickHereToPrint();">Print</a>

<iframe id='ifrmPrint' src='#' style="width:0px; height:0px;"></iframe>


<div id="divToPrint">
content
</div>
</body>

PART 2 - How do I change the file, print menu item to use my part 1 code

window.print?

Thanks

Ray
 
J

Jukka K. Korpela

RAYMOND said:
Hello on my site this is what is happenning

This seems to relate to your previous message "button from this code", with
no reference to it.
Part 1 - This is what works and prints me output I like from <print>
link in body section

You still don't specify a URL or tell what you are actually trying to
accomplish.
<iframe id='ifrmPrint' src='#' style="width:0px;
height:0px;"></iframe>

It looks like you are trying to create problems, instead of solving any. You
can disprove this impression by providing a URL and an understandable
explanation of what you are trying to do (instead of fragments of code
supposed to solve an unspecified problem).
 
C

cwdjrxyz

Hello on my site this is what is happenning

Part 1 - This is what works and prints me output I like from <print> link in
body section

<head>
<script type="text/javascript">
function ClickHereToPrint(){
    try{
        var oIframe = document.getElementById('ifrmPrint');
        var oContent = document.getElementById('divToPrint').innerHTML;
        var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
        if (oDoc.document) oDoc = oDoc.document;
  oDoc.write("<html><head><title>title</title>");
  oDoc.write("</head><body onload='this.focus(); this.print();'>");
  oDoc.write(oContent + "</body></html>");
  oDoc.close();
    }
    catch(e){
     self.print();
    }}

</script>
</head>

<body>

<a onclick="ClickHereToPrint();">Print</a>

 <iframe id='ifrmPrint' src='#' style="width:0px; height:0px;"></iframe>

<div id="divToPrint">
  content
 </div>
</body>

PART 2 -  How do I change the file, print menu item to use my part 1 code

window.print?

Someone will be better able to help if you give the url for a complete
working example without the button. However I will point out that you
are using javascript, and thus your print link will not work for
browsers that have script turned off. See http://www.w3schools.com/browsers/browsers_stats.asp
near the bottom of the page. At one time many turned their script off,
but perhaps only about 5% of visitors to the w3schools site now do.
This may or may not be typical of other sites. In some cases one can
use server side scripting, such as php, to avoid this problem. Also
you might use a no script path that gives text instructions for
printing if there is not script support.
 
R

RAYMOND PISTEY

Fixed it using the browser print, by placing div where i wanted, sorry
newbie here

Hello on my site this is what is happenning

Part 1 - This is what works and prints me output I like from <print> link
in
body section

<head>
<script type="text/javascript">
function ClickHereToPrint(){
try{
var oIframe = document.getElementById('ifrmPrint');
var oContent = document.getElementById('divToPrint').innerHTML;
var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
oDoc.write("<html><head><title>title</title>");
oDoc.write("</head><body onload='this.focus(); this.print();'>");
oDoc.write(oContent + "</body></html>");
oDoc.close();
}
catch(e){
self.print();
}}

</script>
</head>

<body>

<a onclick="ClickHereToPrint();">Print</a>

<iframe id='ifrmPrint' src='#' style="width:0px; height:0px;"></iframe>

<div id="divToPrint">
content
</div>
</body>

PART 2 - How do I change the file, print menu item to use my part 1 code

window.print?

Someone will be better able to help if you give the url for a complete
working example without the button. However I will point out that you
are using javascript, and thus your print link will not work for
browsers that have script turned off. See
http://www.w3schools.com/browsers/browsers_stats.asp
near the bottom of the page. At one time many turned their script off,
but perhaps only about 5% of visitors to the w3schools site now do.
This may or may not be typical of other sites. In some cases one can
use server side scripting, such as php, to avoid this problem. Also
you might use a no script path that gives text instructions for
printing if there is not script support.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top