Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用backbone.js和jQuery时创建新窗口_Javascript_Jquery_Backbone.js_Window.open - Fatal编程技术网

Javascript 使用backbone.js和jQuery时创建新窗口

Javascript 使用backbone.js和jQuery时创建新窗口,javascript,jquery,backbone.js,window.open,Javascript,Jquery,Backbone.js,Window.open,目前,我使用jQuery创建了一个对话框,并使用主干填充它,如下所示: $("#" + dialogID ).html(new MyView({model: MyModels}).el); $( "#" + dialogID ).dialog({ width: 950, height: 500, autoOpen: true, d

目前,我使用jQuery创建了一个对话框,并使用主干填充它,如下所示:

$("#" + dialogID ).html(new MyView({model: MyModels}).el);


$( "#" + dialogID ).dialog({ width: 950,
                           height: 500,
                           autoOpen: true, 
                           dialogClass: dialogID,
                           position: { my: "center", at: "center", of: window },
                           close: function( event, ui ){  
                                                          $(this).remove();
                                                        },
                           title: "My dialog"
                          });
我所要做的就是让它成为一个新窗口,这样用户可以更自由地移动它,所以我尝试:

var w = window.open();
var html = $("#" + dialogID).html();
$(w.document.body).html(new MyView({model: MyModels}).el);
这几乎奏效了。我失去了我的风格和一些功能。有人能建议如何修复此代码段,以便恢复我的样式和功能吗?(例如,我的数据表样式消失,并且与原始窗口中的元素进行了一些交互)


谢谢

我可以向您推荐两种可能的解决方案:

1。在应用程序后端创建一个新路由,该路由将生成包含所需脚本和样式的html页面。完成后,执行与之前相同的操作,但更改
winsow.open('yournewroute')

2.使用所述方法。在纯javascript中,它看起来像

var w = window.open('');
w.document.write('<html><head><title>Dialog</title><link rel="stylesheet" type="text/css" href="styles.css"></head><body>');
w.document.write(new MyView({model: MyModels}).el);
w.document.write('</body></html>');
与样式表相同:

var $stylesheetTags = $('link[rel="stylesheet"]');
$(w.document.head).append($stylesheetTags);

你能给我们提供一个JSFIDLE链接吗?嗨,很抱歉,这与其他代码和本地运行的代码纠缠在一起。如果可能的话,我会尽量提供一些例子,但我希望这与添加windows vs just dialog有明显的关系。嗨,对不起,如果我有很多样式表,我该如何使用jquery?谢谢与使用jQuery操作html标记的方式相同。我已经更新了答案。
var $stylesheetTags = $('link[rel="stylesheet"]');
$(w.document.head).append($stylesheetTags);