LEoREo_2247 LEoREo_2247 - 4 months ago 8
CSS Question

How to convert all "link rel stylesheet" relative path to absolute path in javascript

How I can convert all "link rel stylesheet"in html 's relative path to absolute path using javascript?

before

<link rel="stylesheet" type="text/css" href="/sample.css">


thing i want

<link rel="stylesheet" type="text/css" href="http://sample.com/sample.css">

Answer

Set the href attribute with the href property value:

link.setAttribute("href", link.href); // won't work in old IE

, or set the href property as itself:

link.href = link.href; // maybe different for each browser