0

I have a recipe blog and there is an option to print just the recipe from a blog post, this is all set up and works great, the right stuff gets printed etc using this javascript:

<script type='text/javascript'>

// Print recipe using iframe
function printRecipe(){
var content = document.getElementById(&quot;recipe&quot;);
var pri = document.getElementById(&quot;ifmcontentstoprint&quot;).contentWindow;
pri.document.open();
pri.document.write(content.innerHTML);
pri.document.close();
pri.focus();
pri.print();
}

What I want to do is to add a footer with the website address to the bottom of every 'Print Recipe'. This will be unchanging from recipe to recipe, but I don't want it showing on the original recipe so it needs to show up only when the recipe is printed. So i know i have to add it somewhere in this code, but so far have had no luck.

I have tried to search loads of forums with no real answer to what must be a simply question..

please help! Thanks.

4

1 回答 1

1

在这一行之后:

pri.document.write(content.innerHTML);

添加页脚:

pri.document.write("My custom footer! Can include HTML");

最终代码:

<script type='text/javascript'>

// Print recipe using iframe
function printRecipe(){
var content = document.getElementById("recipe");
var pri = document.getElementById("ifmcontentstoprint").contentWindow;
pri.document.open();
pri.document.write(content.innerHTML);
pri.document.write("My custom footer! Can include HTML");
pri.document.close();
pri.focus();
pri.print();
}
</script>
于 2012-06-25T03:22:05.077 回答