新窗口,内容来自开启页面上的模态内容 [英] New window with content from modal content on opener page

查看:134
本文介绍了新窗口,内容来自开启页面上的模态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我不会这么做,对jquery来说很新。
我有一个隐藏了3个食谱的页面。当点击配方A的链接时,它会以模态打开。我希望能够只打印食谱的内容。所以我打开一个新窗口(非模态)并尝试将配方写入其中(取决于选择的配方)

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)

这是我正在使用的代码

     $('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;

     });

但它返回错误。我认为它很接近但不太正确。错误是:
缺失;在声明之前
[打破此错误] var html =Print ... =myprintrecipe>; \ n

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

推荐答案

我认为你要找的是:

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.

希望这会有所帮助。

这篇关于新窗口,内容来自开启页面上的模态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆