<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>打开窗口测试</title>
<script type="text/javascript">
function openWindow(){
var myWindow = window.open('','','width=400,height=500'),
head = myWindow.document.getElementsByTagName('head')[0],
isIE = function(){
var version = 0, userAgent = navigator.userAgent.toLowerCase();
if (/(msie)\D+(\d[\d.]*)/.test(userAgent)) {
version = RegExp.$2;
}
version = parseInt(version,10);
return version;
}(),
cssURL = 'http://www.yaohaixiao.com/wp-content/themes/BlueNight/style.css';
if(isIE && isIE < 9){
linkTag = myWindow.document.createStyleSheet(cssURL);
}
else{
linkTag = myWindow.document.createElement('link');
linkTag.href = cssURL;
head.appendChild(linkTag);
linkTag.setAttribute('rel','stylesheet');
linkTag.setAttribute('type','text/css');
}
}
</script>
</head>
<body>
<a onClick="openWindow()">打开新窗口</a>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>打开窗口测试</title>
<script type="text/javascript">
function openWindow(){
var myWindow = window.open('','','width=400,height=500'),
head = myWindow.document.getElementsByTagName('head')[0],
isIE = function(){
var version = 0, userAgent = navigator.userAgent.toLowerCase();
if (/(msie)\D+(\d[\d.]*)/.test(userAgent)) {
version = RegExp.$2;
}
version = parseInt(version,10);
return version;
}(),
cssURL = 'http://www.yaohaixiao.com/wp-content/themes/BlueNight/style.css';
if(isIE && isIE < 9){
linkTag = myWindow.document.createStyleSheet(cssURL);
}
else{
linkTag = myWindow.document.createElement('link');
linkTag.href = cssURL;
head.appendChild(linkTag);
linkTag.setAttribute('rel','stylesheet');
linkTag.setAttribute('type','text/css');
}
}
</script>
</head>
<body>
<a onClick="openWindow()">打开新窗口</a>
</body>
</html>
本文介绍了一种在不同浏览器中打开新窗口并设置其样式的方法,特别关注了针对Internet Explorer低版本的兼容性处理。
1947

被折叠的 条评论
为什么被折叠?



