Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  8] [ 3]  / answers: 1 / hits: 36715  / 15 Years ago, tue, august 4, 2009, 12:00:00

i think i am not going about this quite right, being very new to jquery.
i have a page with 3 recipes on it hidden. when a link to recipe A is clicked it opens in a modal. i want to be able to print just the content of the recipe. so i am opening a new window (nonmodal) and trying to write the recipe to it (depending on which recipe is chosen)



this is the code i am using



     $('a.new-window').click(function(){

var recipe = window.open('','RecipeWindow','width=600,height=600');
$('#recipe1').clone().appendTo('#myprintrecipe');
var html = <html><head><title>Print Your Recipe</title></head><body><div id=myprintrecipe></div></body></html>;
recipe.document.open();
recipe.document.write(html);
recipe.document.close();

return false;

});


but it returns an error. i think it is close but not quite right. the error is:
missing ; before statement
[Break on this error] var html = Print...=myprintrecipe>;n


More From » jquery

 Answers
6

I think what you are looking for is the following:



jQuery(function($) {
$('a.new-window').click(function(){

var recipe = window.open('','RecipeWindow','width=600,height=600');
var html = '<html><head><title>Print Your Recipe</title></head><body><div id=myprintrecipe>' + $('<div />').append($('#recipe1').clone()).html() + '</div></body></html>';
recipe.document.open();
recipe.document.write(html);
recipe.document.close();

return false;

});
});


Marius had a partially correct answer - you did have a javascript error in your html string, but the content wouldn't have been appended anyways even if the error didn't get thrown because you were trying to append the recipe before the #myprintrecipe div was even in the new window.



Hope this helps.


[#98996] Friday, July 31, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandra

Total Points: 708
Total Questions: 100
Total Answers: 84

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
sandra questions
Tue, Jun 30, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Fri, May 31, 19, 00:00, 5 Years ago
;