Some common javascript function code _ javascript skills

Source: Internet
Author: User
Changed the ClientMentInfo class to compatible with IE6, IE7, IE8, Vista, Windows7, and Firefox. The Code is as follows:


// Obtain the object
Function getObject (objectId, top)
{
Doc = top? Optional topics top.doc ument: document;
If (typeof (objectId )! = "Object" & typeof (objectId )! = "Function ")
{
If (doc. getElementById & doc. getElementById (objectId ))
{
// W3C DOM
Return doc. getElementById (objectId );
}
Else if (doc. getElementsByName (objectId ))
{
Return doc. getElementsByName (objectId) [0];
}
Else if (doc. all & doc. all (objectId ))
{
// MSIE 4 DOM
Return doc. all (objectId );
}
Else if (doc. layers & doc. layers [objectId])
{
// NN 4 DOM.. note: this won't find nested layers
Return doc. layers [objectId];
}
Else
{
Return false;
}
} Else
Return objectId;
}
// Obtain the relative path
Function getRelativePath ()
{
Var url = location. href; // The current url
Var urlcs = String (location. search );
Url = url. replace (urlcs ,"");
Var path = url. length-url. replace (// g ,""). length-3; // The level is the length of the url containing/-no length of the contained/, and then the number of project headers /.

Var str = "";
For (var I = 0; I <path; I ++)
{
Str + = "../"; // returns the result of combining the string with a relative path.
}
Return str;
}
// Load other JS files or CSS files
Function loadjscssfile (filename, filetype, chkonce)
{
Filetype =! Filetype? "Js": filetype;
Var had = false;
If (filetype = "js ")
{
If (chkonce)
{
Var allScripts = document. getElementsByTagName ("script ");
For (var I = 0; I {
Try {
If (allScripts [I]. src. indexOf (filename)>-1)
{
Had = true;
Break;
}
} Catch (e ){}
}
}
If (! Had)
{
Document. write ("

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.