Javascript 文档。在页面上使用统一字体大小编写新页面
我想打开一个新页面,其内容与旧页面中名为Javascript 文档。在页面上使用统一字体大小编写新页面,javascript,inline-styles,Javascript,Inline Styles,我想打开一个新页面,其内容与旧页面中名为Div1的div相同。 在我的JavaScript函数中,我有一个newWindow变量,该变量由窗口返回。open命令,我将Div1的内部HTML写入newWindow,我希望新页面中的每个文本的字体大小为7px。以下是我写的: newWindow.document.write('<html><head><title>Hello World</title>'); newWindow.docu
Div1
的div
相同。
在我的JavaScript函数中,我有一个newWindow
变量,该变量由窗口返回。open
命令,我将Div1
的内部HTML写入newWindow
,我希望新页面中的每个文本的字体大小为7px。以下是我写的:
newWindow.document.write('<html><head><title>Hello World</title>');
newWindow.document.write('</head><body style="font-size:7px">');
newWindow.document.write($('Div1').html());
newWindow.document.write('</body></html>');
ClasslGends
(仅具有CSS样式的元素类)
你可以试试这个片段。添加实际样式,然后将它们与其他HTML一起附加到文档中。 因此正在阻止打开新窗口,请尝试以下url:
(函数(未定义){
/**
*
*/
"严格使用",;
函数addStyleOnOpen(){
var风格,
样式表,
pageTitle=‘我的标题’,
prnt=open();
style=document.createElement(“style”);
setAttribute('media','all');
style.setAttribute('type','text/css');
setAttribute('rel','stylesheet');
style.appendChild(document.createTextNode(“”);
prnt.document.head.appendChild(样式);
样式表=style.sheet;
stylesheet.insertRule('正文{宽度:100%!重要;边距:0!重要;填充:0!重要;行高:1.45;字体系列:“开放式Sans”,无衬线;颜色:#999;背景:无;字体大小:14pt;}',0);
stylesheet.insertRule('#新窗口{color:green;}',stylesheet.cssRules.length);
insertRule('h1{color:red;}',stylesheet.cssRules.length);
prnt.document.title=页面标题;
prnt.document.body.insertAdjacentHTML('afterbegin','\n Heading\nHello World!
);
}
document.getElementById('new-window')。addEventListener('click',addStyleOnOpen,false);
}(未定义)代码>
您可以尝试此代码段。添加实际样式,然后将它们与其他HTML一起附加到文档中。
因此正在阻止打开新窗口,请尝试以下url:
(函数(未定义){
/**
*
*/
"严格使用",;
函数addStyleOnOpen(){
var风格,
样式表,
pageTitle=‘我的标题’,
prnt=open();
style=document.createElement(“style”);
setAttribute('media','all');
style.setAttribute('type','text/css');
setAttribute('rel','stylesheet');
style.appendChild(document.createTextNode(“”);
prnt.document.head.appendChild(样式);
样式表=style.sheet;
stylesheet.insertRule('正文{宽度:100%!重要;边距:0!重要;填充:0!重要;行高:1.45;字体系列:“开放式Sans”,无衬线;颜色:#999;背景:无;字体大小:14pt;}',0);
stylesheet.insertRule('#新窗口{color:green;}',stylesheet.cssRules.length);
insertRule('h1{color:red;}',stylesheet.cssRules.length);
prnt.document.title=页面标题;
prnt.document.body.insertAdjacentHTML('afterbegin','\n Heading\nHello World!
);
}
document.getElementById('new-window')。addEventListener('click',addStyleOnOpen,false);
}(未定义)代码>
无法在新页面的正文上进行内联样式设置
,但我想我可以更改
newWindow.document.write('</head><body style="font-size:7px">');
newWindow.document.write(“”);
致:
newWindow.document.write('.body{“font size:7px”}');
无法在新页面的正文上进行内联样式设置
,但我想我可以更改
newWindow.document.write('</head><body style="font-size:7px">');
newWindow.document.write(“”);
致:
newWindow.document.write('.body{“font size:7px”}');
您必须向我们展示此处涉及的实际HTML。如果一些HTML标记有自己的字体大小
内联样式设置,或者从具有更高CSS优先级的样式表继承样式,那么
标记上的样式将不会覆盖这些设置。您必须向我们显示此处涉及的实际HTML。如果某些HTML标记有自己的字体大小
内联样式设置,或者从具有更高CSS优先级的样式表继承样式,则
标记上的样式将不会覆盖这些设置。我注意到,因此没有为我打开窗口。我将更新代码段。我注意到了,所以没有为我打开窗口。我将更新代码段。
newWindow.document.write('</head><body style="font-size:7px">');
newWindow.document.write('<style>.body {"font-size:7px"}</style></head><body>');