JS动态给head标签里面添加内容
1、加载不同的css样式
var scrWidth = window.screen.width; //获取当前分辨率的大小
if(scrWidth == 1920){
//当分辨率为1920是应该引入的css
var headHTML = document.getElementsByTagName('head')[0].innerHTML;
headHTML += '<link type="text/css" rel="stylesheet" href="css/style1920.css">';
document.getElementsByTagName('head')[0].innerHTML = headHTML;
}else {
//当分辨率为1366引入的css文件
var headHTML = document.getElementsByTagName('head')[0].innerHTML;
headHTML += '<link type="text/css" rel="stylesheet" href="css/style1366.css">';
document.getElementsByTagName('head')[0].innerHTML = headHTML;
}
2、为seo动态添加canonical标签
$(function(){ var curlink = window.location.href; var headHTML = document.getElementsByTagName('head')[0].innerHTML; headHTML += '<link rel="canonical" href="'+curlink+'">'; document.getElementsByTagName('head')[0].innerHTML = headHTML; })