1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<title>Imprimer une iframe ?</title>
<style media="screen">
#joli {
border: solid 2px #7a4;
background: #cf9;
text-align: center;
width: 500px;
padding: 100px 0;
margin: 1rem 0;
}
</style>
<style media="print">
@page {
size: A4;
margin: 0.4cm;
/* bleed: 100%; */
}
html, body {
margin: 0;
padding: 0;
border: none;
width: 100%;
height: 100%;
overflow: hidden;
}
/* tentative dimprimer 4 pages, mais ça ne marche pas */
/* html, iframe { */
body, iframe {
height: 400%;
}
body > * {
display: none !important;
}
iframe {
display: block !important;
position: absolute;
top: 0;
left: 0;
width: 100%;
margin: 0;
padding: 0;
border: none;
}
</style>
</head>
<body>
<button type="button">Charger une iframe</button>
<div id="joli">Une <code><div></code> pour faire joli</div>
<script> "use strict";
let $button = document.querySelector("button");
$button.addEventListener("click", () => {
$button.disabled = true;
let $iframe = document.createElement("iframe");
$iframe.width = 500;
$iframe.height = 400;
$iframe.onload = () => {
let $p = document.createElement("p");
$p.append("Utilisez la commande « Aperçu avant impression » ;)");
document.body.append($p);
};
$iframe.src = "https://www.developpez.net/forums/";
document.body.append($iframe);
});
</script>
</body>
</html> |
Partager