1

How can i import .css file to .js file ? I m not talking about html page. Html page is not in our control. i m using share point inbuilt page Newform.aspx and applying jslink on this page.

in jslink i have bind Spectrum.js and i want to call Spectrum.css in Spectrum.JS? Is it possible to do this ? i have tried it by many ways but i m not getting proper output.

Kindly reply as soon as possible. Thanks in advance

  • "Html page is not in our control." What do you mean exactly on that? You can edit the built-in SharePoint pages, like NewForm.aspx as well, either from browser or using SharePoint designer. This way you can add a Script Editor web part to the page, and iclude the CSS reference (or further JavaScript files) in the content of that web part. It's not so nice, as the solution from users1100, but it is still possible. – pholpar Jun 22 '16 at 10:13
7

You can put the code of loading external css file in JS only.

Give it a try for below code:

var cssId = 'myCss';   // you could encode the css path itself to generate id..
if (!document.getElementById(cssId))
{
    var head  = document.getElementsByTagName('head')[0];
    var link  = document.createElement('link');
    link.id   = cssId;
    link.rel  = 'stylesheet';
    link.type = 'text/css';
    link.href = 'http://website.com/css/stylesheet.css';
    link.media = 'all';
    head.appendChild(link);
}

hope this helps!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.