Skip to content

Commit b73e25f

Browse files
authored
Merge pull request #3 from ohall-m/windowDotPrint
Adding Printing Examples
2 parents d1cb098 + 7afb54b commit b73e25f

5 files changed

+262
-2
lines changed

index.html

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ <h1>Test Website</h1>
77
<li><a href="/getcurrentlocation.html">Testing Geolocation Get Current Position</a></li>
88
<li><a href="/watchposition.html">Testing Geolocation Watch Position</a></li>
99
<li><a href="/printtest.html">Print Test</a></li>
10-
<li><a href="/print_iframe.html">IframePrint Test</a></li>
10+
<li><a href="/print_iframe.html">iFramePrint Test</a></li>
1111
<li><a href="/print_content_change.html">Print Context Change</a></li>
12+
</ul>
1213

13-
14+
<h2>Printing Tests</h2>
15+
<ul>
16+
<li><a href="/simple_print.html">Simple Print</a></li>
17+
<li><a href="/simple_media_query.html">Simple Print Media Query</a></li>
18+
<li><a href="/new_tab_print.html">New Tab Print</a></li>
19+
<li><a href="/new_tab_print_close.html">New Tab Print Close</a></li>
20+
<li><a href="/print_iframe.html">iFramePrint Test</a></li>
21+
<li><a href="/print_content_change.html">Print Context Change</a></li>
1422
</ul>
1523
</body>
1624
</html>

new_tab_print.html

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8" content="width=device-width, height=device-height">
6+
<title>New Tab Print</title>
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
8+
</head>
9+
10+
<style>
11+
.box {
12+
height: 50vh;
13+
width: 50vw;
14+
}
15+
.background{
16+
background-color: rgb(0, 0, 255);
17+
color-adjust: exact;
18+
}
19+
20+
</style>
21+
22+
<script>
23+
function specialPrint() {
24+
const myWindow = window.open();
25+
myWindow.document.write("<html><head><title>Print New Tab</title></head>");
26+
myWindow.document.write("<h1>New Tab Print</h1>");
27+
myWindow.document.write("<p> This website sends the user out to a new tab to print.</p>");
28+
myWindow.document.write("<h2>Info</h2>");
29+
myWindow.document.write("<ul><li>List 1</li><li>List 2</li><li>List 3</li></ul> ");
30+
myWindow.document.write("<p>When you print this window, it will not close afterward.</p>");
31+
myWindow.document.write("</body></html>");
32+
myWindow.print();
33+
}
34+
</script>
35+
36+
<div class="container">
37+
<h1 class="pt-4 ">New Tab Print</h1>
38+
<div class="alert alert-primary" role="alert">
39+
Just a banner.
40+
</div>
41+
42+
<h2>Print</h2>
43+
<div class="row">
44+
<div class="col-6">
45+
<button class="btn btn-primary btn-lg" onclick="specialPrint();">Print Page</button>
46+
</div>
47+
</div>
48+
49+
<h2>Info</h2>
50+
<p>
51+
This is a simple print test. This website opens a new tab for printing. It does not take care of closing the window.
52+
</p>
53+
<ul>
54+
<li>List 1</li>
55+
<li>List 2</li>
56+
<li>List 3</li>
57+
</ul>
58+
59+
60+
</div>
61+
</html>

new_tab_print_close.html

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8" content="width=device-width, height=device-height">
6+
<title>New Tab Print</title>
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
8+
</head>
9+
10+
<style>
11+
.box {
12+
height: 50vh;
13+
width: 50vw;
14+
}
15+
.background{
16+
background-color: rgb(0, 0, 255);
17+
color-adjust: exact;
18+
}
19+
20+
</style>
21+
22+
<script>
23+
function printAndClose() {
24+
const myWindow = window.open();
25+
myWindow.document.write("<html><head><title>Print New Tab Close</title></head>");
26+
myWindow.document.write("<h1>New Tab Print</h1>");
27+
myWindow.document.write("<p> This website sends the user out to a new tab to print.</p>");
28+
myWindow.document.write("<h2>Info</h2>");
29+
myWindow.document.write("<ul><li>List 1</li><li>List 2</li><li>List 3</li></ul> ");
30+
myWindow.document.write("<p>When you print this window, it will close afterward.</p>");
31+
myWindow.document.write("</body></html>");
32+
myWindow.print();
33+
myWindow.close();
34+
}
35+
</script>
36+
37+
<div class="container">
38+
<h1 class="pt-4 ">New Tab Print</h1>
39+
<div class="alert alert-primary" role="alert">
40+
Just a banner.
41+
</div>
42+
43+
<h2>Print</h2>
44+
<div class="row">
45+
<div class="col-6">
46+
<button class="btn btn-primary btn-lg" onclick="printAndClose();">Print Page</button>
47+
</div>
48+
</div>
49+
50+
<h2>Info</h2>
51+
<p>
52+
This is a simple print test. This website opens a new tab for printing. It also takes care of closing the window.
53+
</p>
54+
<ul>
55+
<li>List 1</li>
56+
<li>List 2</li>
57+
<li>List 3</li>
58+
</ul>
59+
60+
</div>
61+
</html>

simple_media_query.html

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8" content="width=device-width, height=device-height">
6+
<title>Simple Print Media Query</title>
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
8+
</head>
9+
<style>
10+
.box {
11+
height: 50vh;
12+
width: 50vw;
13+
}
14+
@media screen {
15+
.background{
16+
background-color: rgb(0, 0, 255);
17+
color-adjust: exact;
18+
}
19+
.only-print {
20+
display: none !important;
21+
}
22+
}
23+
@media print {
24+
.background{
25+
background-color: rgb(255, 113, 57);
26+
color-adjust: exact;
27+
}
28+
.no-print, .no-print * {
29+
display: none !important;
30+
}
31+
}
32+
</style>
33+
<div class="container">
34+
<h1 class="pt-4 ">Printing CSS Included</h1>
35+
<div class="alert alert-primary no-print" role="alert">
36+
Just a banner that will hide when printing due to CSS media queries
37+
</div>
38+
39+
<h2 class="no-print">Print</h2>
40+
<div class="no-print row" >
41+
<div class="col-6 no-print">
42+
<button class="btn btn-primary btn-lg" onclick="window.print();">Print Page</button>
43+
</div>
44+
</div>
45+
46+
<h2>Info</h2>
47+
<p>
48+
This is a simple print test. There are some CSS media queries that change the way the website will appear when printing versus on the screen!
49+
</p>
50+
51+
<p>This is the ideal way to print!</p>
52+
<p class="only-print">
53+
Notice a lot of things changed in the print layout to optimize for printing. The banner was removed, as well as the print button, and some thins appeared.
54+
</p>
55+
56+
<h2 class="only-print">List Only Appears in Print</h2>
57+
<p class="only-print">The list is set to only appear during printing.</p>
58+
<ul class="only-print">
59+
<li>Print List 1</li>
60+
<li>Print List 2</li>
61+
<li>Print List 3</li>
62+
</ul>
63+
64+
65+
<h2>Print CSS Media Query Box</h2>
66+
<p>
67+
The box below has a <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/Printing#using_media_queries_to_improve_layout">print css media</a> query.
68+
</p>
69+
<p>
70+
It will appear blue on screen and orange in print.
71+
</p>
72+
<div id="content" class="box background">
73+
</div>
74+
75+
</div>
76+
</html>

simple_print.html

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8" content="width=device-width, height=device-height">
6+
<title>Simple Print Test</title>
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
8+
</head>
9+
10+
<style>
11+
.box {
12+
height: 50vh;
13+
width: 50vw;
14+
}
15+
.background{
16+
background-color: rgb(0, 0, 255);
17+
color-adjust: exact;
18+
}
19+
20+
21+
</style>
22+
23+
<div class="container">
24+
<h1 class="pt-4 ">Simple Print Test</h1>
25+
<div class="alert alert-primary" role="alert">
26+
Just a banner.
27+
</div>
28+
29+
<h2>Print</h2>
30+
<div class="row">
31+
<div class="col-6">
32+
<button class="btn btn-primary btn-lg" onclick="window.print();">Print Page</button>
33+
</div>
34+
</div>
35+
36+
<h2>Info</h2>
37+
<p>
38+
This is a simple print test. This website prints the page as-is without opening a new tab to add formatting.
39+
</p>
40+
<ul>
41+
<li>List 1</li>
42+
<li>List 2</li>
43+
<li>List 3</li>
44+
</ul>
45+
46+
<h2>Blue Box</h2>
47+
<p>
48+
Just printing a background.
49+
</p>
50+
<div id="content" class="box background">
51+
</div>
52+
53+
</div>
54+
</html>

0 commit comments

Comments
 (0)