Custom print preview page with php and javascript - php

I would like to know if there is a way to customize the print preview page. I have a button on my page "Print page" and if I press it, I will get the print preview page. In this page there are some informations of users. I want to verify if the user that clicks this button is logged in and if so, in the print preview page will be only his informations. Thanks

You can set a specific print CSS style sheet. This could hide or show some things which should be hidden or only shown on the print output. This "print" style sheet does not affect the normal browser view.
Example HTML:
<div id="navigation">HOME</div>
<div id="print_copy_right" style="display:none">(c) domain.com</div>
Example CSS:
#media print {
#navigation_bar {display:none}
#print_copy_right {display:block}
}

Related

How to add popup on close a browser tag ,inside a popup show img,when we clik this ,it hide and show a div message

i want to two popup show when close a browser tag of site
1.leave and stay confirmation.and
2. for showing a image inside this ,when we click on this ,it hide and show a warning message on top of header,like this http://eyetensive.com/aa/
Pls help soon
You need to bind to the window unload and show your modal.
Lets say this is the html you want to show called "showme" which is hidden with hide class then the following will show the html and show the alert message when the user attempts to leave.
<div id="showme" class="hide">
<h1>I am now shown!</h1>
</div>
<style>.hide {display:none}</style>
<script>
window.onbeforeunload = function(e) {
document.getElementById("showme").className = ""; // remove class
return 'Do you want leave.'; // firefox shows custom text that can't be changed
};
</script>

How can I include this in a Jquery lightbox or dialog box?

Is this technically possible in Jquery .. Basically I'd like to call a php page inside or a lightbox or a Jquery Dialog pop up when a user clicks on an image hyperlink or a link
For example , I have this this line of code .. Once a user clicks on this image link , a dialog or light box should appear with the content of the profiles.php page .. How can I implement this in Jquery .. I'm too new to Jquery .. but how would I go about doing this ? I'd really appreciate it .. I need guidance on how to make the profiles.php info load into a dialog or lightbox .. whichever of the two options is appropriate for it.
echo "<a href='profiles.php'><img src='boy.jpg'width='100' height='100' class='image' /></a>";
Try Fancybox ! Its a jquery plugin!
For usage instructions visit : http://fancybox.net/howto
You could use jQuery.load(url) method read more: http://api.jquery.com/load/
jQuery('a.linkclass').click(function(event){
event.preventDefault();// prevent link default action
jQuery('selection of where you need to load content').load('profiles.php');
});
Not sure if it works 100% haven't tested it
Load Colorbox on your page
add class colorbox-html to the hyperlink
add <script>$('a.colorbox-html').colorbox();</script> to the bottom of your page
Click the link
Disclaimer: This hasn't been tested

PHP/Javascript Bypass user input to display div

I have a page where if you click on a link, it exposes a div that using ajax displays content from a dbase.
After a user edits this content on the server, I'd like to use PHP to return the user to that page. This is no problem using a redirect
header("location:page.php")
However, when the user comes back to the page, ideally, I'd like to have the content in the div open automatically so the user can immediately see edits without having to find the link to open the div and click on it.
Is this possible, either with something in the url to fire the javascript or alternaively, when you load the page with a certain parameter, triggering javascript to open the div.
The code to open the div is a simple javascript call:
View Content
showDiv just uses ajax to display something from the server using responsetext.
Thanks for any suggestions
header("location:page.php?show=1")
Then in page.php body tag:
<body <?php if($_GET['show']==1) { ?>onload="showDiv()"<?php } ?>>

Print to paper selected data

I've a database (image1) and using PHPMaker i created the graphic interface (image2). What i want is to add a button at the bottom of the page that will print the selected data from the selected fields (image3).
Can anyone tell me how to do that?
Do i have to use php code or a javascript?
Just add a print link by echoing the following to create a "Print" link on the page
echo "<a href='#' onclick='javascript:window.print();'>Print Page</a>";
Button click will make the browser present the user with the default print dialog.

How to add a print button to a web page

On one of my pages in my website(coded in php), i'm trying to add 2 (even more) print buttons each one printing a portion of the webpage. For example, on a page there is a table with some values and 2 graphs underneath it. I would like to add 2 print buttons, one button printing the table and the other one printing both the graphs. I've found this Example but could not understand clearly. Any help or examples would help me.
Thanks in advance.
This is html/javascript code that will launch the browser's Print dialog when clicked.
<button onClick="window.print()">Print this page</button>
If your table is inside a div with id='printTable' use:
Click to print table
EDIT: Here is the function "printContent()"
<script type="text/javascript">
<!--
function printContent(id){
str=document.getElementById(id).innerHTML
newwin=window.open('','printwin','left=100,top=100,width=400,height=400')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('<TITLE>Print Page</TITLE>\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')
newwin.document.write(str)
newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
}
//-->
</script>
A simple idea is to create some previous css printing rules ad hoc, e.g.
.printtable * { display : none; }
.printtable table { display : block; }
and
.printtableandgraph * { display : none; }
.printtableandgraph img { display : block; }
then the two buttons should add a .printtable and a .printtableandgraph class for the body element (or other element containing your table and graphs) just before window.print() statement
(if user click twice or more on the same print button check previously if the element has already set that class name)
Print Button
<button onClick="window.print()">Print this page</button>`
Use This code for print any webpage there is only one draw back its print all the button and menu bar.
To print a portion of the page, you can use a print.css and the print button for a quick and simple approach.
Set up print.css file and include:
body {visibility:hidden;}
.print {visibility:visible;}
Add the .print class to the appropriate portions of your page.
Add button:
<button onClick="window.print()">Print this page ยป</button>
Print results are neat and clean.

Categories