js 判斷瀏覽器類型 去全角、半角空格 自動關閉當前窗口
更新時間:2009年04月10日 19:41:11 作者:
去全角、半角空格 自動關閉當前窗口等實現函數。
// 判斷瀏覽器類型
function GetIEType()
{
var Sys = {};
var nvg = navigator.userAgent.toLowerCase();
var rslt;
if (window.ActiveXObject)
{
Sys.ie = nvg.match(/msie ([\d.]+)/)[1];
}
(rslt = nvg.match(/firefox\/([\d.]+)/)) ? Sys.firefox = rslt[1] :
(rslt = nvg.match(/chrome\/([\d.]+)/)) ? Sys.chrome = rslt[1] :
(rslt = nvg.match(/version\/([\d.]+).*safari/)) ? Sys.safari = rslt[1] : 0;
if (Sys.ie)
{
alert('IE: '+ Sys.ie);
}
if (Sys.firefox)
{
alert('Firefox: ' + Sys.firefox);
}
if (Sys.chrome)
{
alert('Chrome: ' + Sys.chrome);
}
if (Sys.safari)
{
alert('Safari: ' + Sys.safari);
}
}
// 去文全角半角空格------------------------
// 使用時將"丂"替換成全角空格
String.prototype.trim = function()
{
return this.replace(/[丂*]|[ *]/g,"");
}
// 去左空格
String.prototype.ltrim = function()
{
return this.replace(/^[丂*]|[ *]/g,"");
}
// 去右空格
String.prototype.rtrim = function()
{
return this.replace(/[丂*]|[ *]*$/,"");
}
// 匹配Email格式
function check_email(email)
{
if( email.match(/^[-+0-9a-z.=_\/]+@([-0-9a-z]+\.)+[a-z]{2,6}$/i) )
return true;
else
{
alert( "Error!");
return false;
}
}
// 自動關閉當前窗口
window.onload = function()
{
window.setTimeout("next();",3000);
};
function next()
{
alert("OK");
}
function GetIEType()
{
var Sys = {};
var nvg = navigator.userAgent.toLowerCase();
var rslt;
if (window.ActiveXObject)
{
Sys.ie = nvg.match(/msie ([\d.]+)/)[1];
}
(rslt = nvg.match(/firefox\/([\d.]+)/)) ? Sys.firefox = rslt[1] :
(rslt = nvg.match(/chrome\/([\d.]+)/)) ? Sys.chrome = rslt[1] :
(rslt = nvg.match(/version\/([\d.]+).*safari/)) ? Sys.safari = rslt[1] : 0;
if (Sys.ie)
{
alert('IE: '+ Sys.ie);
}
if (Sys.firefox)
{
alert('Firefox: ' + Sys.firefox);
}
if (Sys.chrome)
{
alert('Chrome: ' + Sys.chrome);
}
if (Sys.safari)
{
alert('Safari: ' + Sys.safari);
}
}
// 去文全角半角空格------------------------
// 使用時將"丂"替換成全角空格
String.prototype.trim = function()
{
return this.replace(/[丂*]|[ *]/g,"");
}
// 去左空格
String.prototype.ltrim = function()
{
return this.replace(/^[丂*]|[ *]/g,"");
}
// 去右空格
String.prototype.rtrim = function()
{
return this.replace(/[丂*]|[ *]*$/,"");
}
// 匹配Email格式
function check_email(email)
{
if( email.match(/^[-+0-9a-z.=_\/]+@([-0-9a-z]+\.)+[a-z]{2,6}$/i) )
return true;
else
{
alert( "Error!");
return false;
}
}
// 自動關閉當前窗口
window.onload = function()
{
window.setTimeout("next();",3000);
};
function next()
{
alert("OK");
}
相關文章
javascript SocialHistory 檢查訪問者是否訪問過某站點
今天delicious上這個名為 SocialHistory 的腳本十分引人注目。源代碼可以在這里下載。這段js代碼的功能就是判斷你的用戶有沒有訪問過某個網站。使用方法很簡單,例如:2008-08-08

