Javascript JS:window.open-如何设置opensans字体?

Javascript JS:window.open-如何设置opensans字体?,javascript,printing,font-family,Javascript,Printing,Font Family,我不能让它工作。我唯一需要的是-将所有内容字体系列设置为'opensans'。这是我现在拥有的 var popupWin = window.open('', '_blank', 'width="100%",height="100%"'); popupWin.document.write('<html><head><link href=\'http://fonts.googleapis.com/css?family=Open+Sans\

我不能让它工作。我唯一需要的是-将所有内容字体系列设置为
'opensans'
。这是我现在拥有的

        var popupWin = window.open('', '_blank', 'width="100%",height="100%"');
        popupWin.document.write('<html><head><link href=\'http://fonts.googleapis.com/css?family=Open+Sans\' rel=\'stylesheet\' type=\'text/css\'></head><body>' + content + '</body></html>');
        popupWin.document.body.setAttribute('style', 'font-family: \'Open Sans\' !important');
        popupWin.document.close();
        popupWin.print();
        popupWin.close();
    }
var popupWin=window.open('''.'空白','宽度=100%,高度=100%');
popupWin.document.write(“”+内容+“”);
popupWin.document.body.setAttribute('style','font-family:\'opensans\'!important');
popupWin.document.close();
popupWin.print();
popupWin.close();
}
这段代码显示的是空页面,但当我删除
链接
属性时,显示的是内容,但带有默认的族。有什么想法吗

p.S.content变量包含一个简单的html标记,我试图设置如下样式


但是运气不好。

http
更改为
https
。您可能还希望在打印前添加延迟。请尝试以下操作:

document.querySelector('button')。onclick=function(){
var content=document.querySelector('textarea').innerHTML;
var popupWin=window.open(“,”u blank“,”width=“100%”,height=“100%”);
//浏览器锁定的弹出窗口
如果(!popupWin){
log(“弹出窗口被阻止”);
返回false;
}
popupWin.document.write(“”+内容+“”);
popupWin.document.body.setAttribute('style','font-family:'opensans'!important');
setTimeout(函数(){
popupWin.document.close();
popupWin.print();
popupWin.close();
}, 2000);
};
测试
把这个放在弹出页面上

打印
是否从HTTPS选项卡打开页面?如果是,浏览器将阻止您的请求“http://....". 尝试删除protocoll
href=\'//font.googleapis.com/css?family=Open+Sans\'
是的,我使用的是HTTPs,但是我如何删除协议,Open Sans不是标准字体,我必须上传它。注释向您展示了如何删除协议。只需从
href
属性的开头删除
http:
(保留斜杠)。这只会给我一个空白屏幕,没有显示任何内容。这很奇怪,但问题只有在添加延迟后才消失,你能解释为什么吗?我想打印功能没有等待加载资源。@Stifle:你是说这个吗<代码>如果(!popupWin){