且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

新窗口,内容来自开启页面上的模态内容

更新时间:2023-12-03 08:01:34

我认为你要找的是:

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有一个部分正确的答案 - 你的html字符串确实有一个javascript错误,但内容即使错误没有被抛出也不会被追加,因为你试图在#myprintrecipe div甚至在新窗口之前附加食谱。

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.

希望这会有所帮助。