Call css dynamically from javascript code based on screen resolutions

Below is the code which shows the way to dynamically call respective CSS file based on screen resolution using javascript. The implementation of CSS files is user specific.

FIle Name: Resolution.js


 
Code:

if (screen.width == 800) {
document.write('<link rel="stylesheet" href="/css/800.css">');

}
 else if (screen.width == 1024) {
document.write('<link rel="stylesheet" href="/css/1024.css">');

}
 else if (screen.width == 1152) {
document.write('<link rel="stylesheet" href="/css/1152.css">');
}

else if (screen.width == 1280) {
document.write('<link rel="stylesheet" href="/css/1280.css">');
}

else{document.write('<link rel="stylesheet" href="/css/1024.css">');}

No comments:

Post a Comment