简体   繁体   English

使用 JavaScript 在 Internet Explorer 中插入外部 CSS

[英]Inserting external CSS in Internet Explorer using JavaScript

I am trying to load external CSS into Internet explorer using console.我正在尝试使用控制台将外部 CSS 加载到 Internet Explorer。 When I write the injection code, it says there is a Syntax error.当我编写注入代码时,它说存在语法错误。

$(document.head).append('<link rel="stylesheet" href="http://fahaduddin.com/css-new/mystyles.css">');

You can use this code:您可以使用此代码:

var element = document.createElement("link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("type", "text/css");
element.setAttribute("href", "external.css");
document.getElementsByTagName("head")[0].appendChild(element);

Here's a simpler and I'm pretty sure faster way of doing this...这是一个更简单的方法,我很确定这样做会更快......

var style_link = document.createElement('link');
style_link.ref = 'stylesheet';
style_link.href = 'http://fahaduddin.com/css-new/mystyles.css';
document.head.append(style_link);

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

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