javascript - javascript中子窗口如何从父窗口继承css样式?
问题描述
我编写了一个函数来创建一个新窗口(子窗口)。
openReportsWindow:function(content){
window.name = "parentWin";
var h = screen.height;
var w = screen.width;
if(window.childWrep == null){
var childWrep = window.open("", 'repWin','left=0,top=0,resizable=yes,status=yes,width='+w +',height=' +h+'');
childWrep.document.write(content);
childWrep.document.close();
childWrep.name = 'repWin';
window.childWrep = childWrep;
} else {
window.blur();
if(window.childWrep.closed == false){
childWrep.document.write(content);
childWrep.document.close();
setTimeout(function(){window.childWrep.focus()},1000);
} else{
var childWrep = window.open("", 'repWin','left=0,top=0,resizable=yes,status=yes,width='+w +',height=' +h+'');
childWrep.document.write(content);
childWrep.document.close();
childWrep.name = 'repWin';
window.childWrep = childWrep;
}
}
}
并以这种方式将html放入这个子窗口。
render : function() {
var context = {
data: data
...
};
this.openReportsWindow(this.template(context));
}
这是问题所在。你如何从父窗口继承css样式?以及如何在子窗口中触发事件?
解决方案
要复制父样式,您可以使用 .style 属性,只需为父元素和子元素使用元素选择器,并将 child.style 属性分配给 parents.style。
例子:
let $parent = document.getElementById('parenID')
let $child = document.getElementById('childID')
$child.style = parent.style
推荐阅读
- javascript - 如何从 asyn/await 函数将值返回给全局变量?
- amazon-web-services - 重复的 SQS 消息可以持续多长时间?
- java - Java,DateTimeFormatter 不考虑 ZoneDateTime 的时区
- tmux - tmux - 为每个命令强制重复前缀键
- r - 使用 R 有效地计算列中单词列表的出现次数
- java - CLion 插件开发:如何向现有方法添加方法调用
- c# - 从 c# 中的泛型类返回列表但列表(协变)没有在主类中更新?
- docker - 如何加载下载的图像,通过 ansible playbook 在 docker 容器中运行它
- javascript - 如何在Javascript正则表达式中提取引号之间的文本
- mysql - 分组计数?