简体   繁体   English

如何将新的Web字体绑定到打开的html页面?

[英]How to bind a new web font to an open html page?

i'm not sure if it's the right place to post this question ? 我不确定是否是发布此问题的正确地方?

I've read this morning that the new version of Chrome support live binding web font. 今天早上我读到,新版的Chrome支持实时绑定网络字体。

Is there a trick javascript, dom manipulation, Amberjs or Jquery plug-in to do the same to the browser that doesn't support that feature yet (to add a new web font in a open page in the browser and have access to it, i mean without to have to change the css and reload the page ?) 是否有技巧性的javascript,dom操作,Amberjs或Jquery插件可以对尚不支持该功能的浏览器执行相同的操作(在浏览器的打开页面中添加新的Web字体并可以访问它,我的意思是不必更改CSS并重新加载页面?)

thanks :) 谢谢 :)

Try this: 尝试这个:

var newStyleText = "@font-face {" +
"font-family: myFirstFont;" +
"src: url(your-font.css);" +
"}"

var newStyle = $(document.createElement("style");
newStyle.html(newStyleText);
$(document.head).append(newStyle)

every element with font-family: myFirstFont; 每个带有font-family: myFirstFont;元素font-family: myFirstFont; while use your font! 同时使用您的字体!

As @Mohsen89z said, you can use @font-face. 正如@ Mohsen89z所说,您可以使用@ font-face。

Cite from w3schools: 引用w3schools:

The @font-face rule is supported in Internet Explorer 9, Firefox, Opera, Chrome, and Safari. Internet Explorer 9,Firefox,Opera,Chrome和Safari支持@ font-face规则。

Internet Explorer 9+, Firefox, Chrome, Safari, and Opera support the WOFF (Web Open Font Format) font. Internet Explorer 9 +,Firefox,Chrome,Safari和Opera支持WOFF(Web开放字体格式)字体。

Firefox, Chrome, Safari, and Opera also support fonts of type TTF (True Type Fonts) and OTF (OpenType Fonts). Firefox,Chrome,Safari和Opera也支持TTF(True Type字体)和OTF(OpenType字体)类型的字体。

Chrome, Safari and Opera also support SVG fonts/shapes. Chrome,Safari和Opera也支持SVG字体/形状。

Internet Explorer also supports EOT (Embedded OpenType) fonts. Internet Explorer还支持EOT(嵌入式OpenType)字体。

Note: Internet Explorer 8 and earlier versions, do not support the @font-face rule. 注意:Internet Explorer 8和更早版本不支持@ font-face规则。

Anyway, there is a trick to use on IE previous versions. 无论如何,在IE早期版本上有一个技巧。 Check this link . 检查此链接

Then, if you want to change the font, use JS for that. 然后,如果要更改字体,请使用JS。 Example with jQuery: jQuery示例:

$('.myparagraph').css('font', 'normal "Your fav font", sans-serif');

To extend my asnwer, I recommend you to use Google Fonts to embed all fonts that you need into a single tag line, like: 为了扩展功能,建议您使用Google字体将所需的所有字体嵌入到单个标记行中,例如:

<link href='http://fonts.googleapis.com/css?family=Finger+Paint|Gloria+Hallelujah|Open+Sans' rel='stylesheet' type='text/css'>

Then, you can use it directly from your css .mydiv { font-family: "Open Sans", sans-serif; } 然后,您可以直接在css .mydiv { font-family: "Open Sans", sans-serif; }使用它.mydiv { font-family: "Open Sans", sans-serif; } .mydiv { font-family: "Open Sans", sans-serif; } or js (example above) .mydiv { font-family: "Open Sans", sans-serif; }或js(上面的示例)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM