JS関数ライブラリのcommon.js
/************************************************************
$(id) id
GetLen(str) ,
InitHeight(obj) Iframe ,Iframe
Close() ,FF
GetElementByName(name, i) , ,i
ArrayRemove(array, n)
************************************************************/
function $(id)
{
return document.getElementById(id);
}
function GetLen(str)
{
return str.replace(/[^\x00-\xff]/g, '**').length;
}
function InitHeight(obj)
{
obj.style.height = (obj.contentWindow.document.body.scrollHeight + 20) + 'px';
}
function Close()
{
window.opener = null;
window.open('', '_self');
window.close();
}
//
function GetElementByName(name, i)
{
if (typeof(i) == 'undefined') i = 0;
var els = document.getElementsByName(name);
if (els.length > 0)
{
return els[i];
}
return null;
}
function ArrayRemove(array, n)
{
if(n < 0 || n >= array.length) return array;
// slice
// concat
return array.slice(0, n).concat(array.slice(n + 1, array.length));
}
/************************************************************
Cookie 。
: Cookie。
1.Cookie.Exist(name) Cookie
2.Cookie.Get(name) Cookie , Cookie null
3.Cookie.Remove(name, path, domain) Cookie
4.Cookie.Add(name, value, expires, path, domain, secure) Cookie,
5.Cookie.Append(name, value) , "|"
************************************************************/
var Cookie =
{
Expires : 365,
Exist : function(name)
{
if (this.Get(name)) return true;
return false;
},
Get : function(name)
{
var strCookies = document.cookie;
var cookieName = name + '='; // Cookie
//
var valueBegin = strCookies.indexOf(cookieName);
if (valueBegin == -1) return null; // Cookie
//
var valueEnd = strCookies.indexOf(';', valueBegin);
if (valueEnd == -1) valueEnd = strCookies.length; // Cookie
// Cookie
var value = strCookies.substring(valueBegin + cookieName.length, valueEnd);
return value;
},
Add : function(name, value, expires)
{
if (typeof(expires) == 'undefined') expires = this.Expires;
var strCookie = name + '=' + value;
if (expires)
{
// Cookie ,
var curTime = new Date();
curTime.setTime(curTime.getTime() + expires*24*60*60*1000);
strCookie += '; expires=' + curTime.toGMTString();
}
document.cookie = strCookie;
},
Append : function(name, value, expires) // “|”
{
var oldValue = this.Get(name);
if (oldValue != null) value = oldValue + '|' + value;
this.Add(name, value, expires);
},
Remove : function(name)
{
var strCookie;
// Cookie
if (this.Exist(name))
{
// Cookie
strCookie = name + '=;';
document.cookie = strCookie;
}
}
}
/************************************************************
Ajax 。
: XMLHttpRequest, Ajax
Ajax.LoadXml(url, method, callback)
url
method , GET POST
callback , ,
************************************************************/
var Ajax =
{
LoadXml : function(url, method, callback)
{
var xmlHttp;
if (window.ActiveXObject) // IE
{
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
else if (window.XMLHttpRequest) // FF
{
xmlHttp = new XMLHttpRequest();
}
if(!xmlHttp)
{
window.alert(' XMLHttpRequest !');
return false;
}
xmlHttp.open(method, url, true);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState != 4) return;
callback(xmlHttp);
}
xmlHttp.send(null);
}
}
2010.1.9追加:
// url
function getArgs( ) {
var args = new Object( );
var query = location.search.substring(1); // Get query string
var pairs = query.split("&"); // Break at ampersand
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); // Look for "name=value"
if (pos == -1) continue; // If not found, skip
var argname = pairs[i].substring(0,pos); // Extract the name
var value = pairs[i].substring(pos+1); // Extract the value
value = decodeURIComponent(value); // Decode it, if needed
args[argname] = value; // Store as a property
}
return args; // Return the object
}
function GetQueryString( sProp ) {
var re = new RegExp( sProp + "=([^\\&]*)", "i" );
var a = re.exec( document.location.search );
if ( a == null )
return "";
return a[1];
};
2010-12-11
function clickForAuto(){
var nodeId = "test";
if(document.all){
document.getElementById(nodeId).click();
}else{
var evt = document.createEvent("MouseEvents");
evt.initEvent("click", true, true);
document.getElementById(nodeId).dispatchEvent(evt);
}
}