11. Native JavaScript add to Favorite folder
function Addfavorite (sURL, stitle) { try { window.external.addFavorite (sURL, stitle) } catch (e) { try { Window.sidebar.addPanel (stitle, sURL, "") } catch (e) { alert ("Failed to bookmark, use Ctrl+d to add")} } }
12. Native JavaScript Set as homepage
functionsetHomePage () {if(document.all) {Document.body.style.behavior= ' url (#default #homepage) '; Document.body.setHomePage (' http://www.cnblogs.com/LoveOrHate/') } Else if(Window.sidebar) {if(window.netscape) {Try{Netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect") } Catch(e) {alert ("This action is rejected by the browser, if you want to enable the feature, enter About:config in the Address bar, and then signed.applets.codebase_principal_support the item value to True") } } varPrefs = components.classes[' @mozilla. Org/preferences-service;1 '].getservice (Components.interfaces.nsIPrefBranch); Prefs.setcharpref (' Browser.startup.homepage ', ' http://www.cnblogs.com/LoveOrHate/') }}
13. Native JavaScript judgment IE6
var ua = navigator.userAgent.toLowerCase (); var isIE6 = Ua.indexof ("MSIE 6") >-1; if (isIE6) { try { Document.execcommand (falsetrue) Catch (e) {}}
14, native JavaScript load style file
function loadstyle (URL) { try { document.createstylesheet (URL) catch( e) { var csslink = document.createelement (' link '); = ' stylesheet '; = ' Text/css '; = URL; var head = document.getElementsByTagName (' head ') [0]; Head.appendchild (Csslink) }}
15. Native JavaScript returns script content
functionEvalscript (s) {if(S.indexof (' <script ') = =-1)returns; varp =/<script[^\>]*?> ([^\x00]*?) <\/script>/IG; vararr = []; while(arr =p.exec (s)) {varP1 =/<script[^\>]*?src=\ "([^\>]*?) \ "[^\>]*? (reload=\ "1\")? (?: Charset=\ "([\w\-]+?) \ ")? ><\/script>/i; varARR1 = []; ARR1= P1.exec (arr[0]); if(arr1) {appendscript (arr1[1], ", arr1[2], arr1[3]); } Else{P1=/<script (. *?) > ([^\x00]+?) <\/script>/i; ARR1= P1.exec (arr[0]); Appendscript (", Arr1[2], Arr1[1].indexof (' reload= ')! =-1); } } returns;}
16. Native JavaScript clears script content
function Stripscript (s) { return s.replace (/<script.*?>.*?<\/script>/ig, ');}
17. Native JavaScript dynamic load script file
functionappendscript (src, text, reload, CharSet) {varid = hash (src +text); if(!reload && in_array (ID, evalscripts))return; if(Reload &&$ (ID)) {$ (ID). Parentnode.removechild ($ (ID)); } evalscripts.push (ID); varScriptnode = document.createelement ("Script"); Scriptnode.type= "Text/javascript"; Scriptnode.id=ID; Scriptnode.charset= CharSet? CharSet: (Browser.firefox?document.characterSet:document.charset); Try { if(SRC) {scriptnode.src=src; Scriptnode.onloaddone=false; Scriptnode.onload=function() {Scriptnode.onloaddone=true; JSLOADED[SRC]= 1; }; Scriptnode.onreadystatechange=function () { if(Scriptnode.readystate = = ' Loaded ' | | scriptnode.readystate = = ' complete ') &&!scriptnode.onloaddone) {Scriptnode.onloaddone=true; JSLOADED[SRC]= 1; } }; } Else if(text) {Scriptnode.text=text; } document.getelementsbytagname (' head ') [0].appendchild (Scriptnode); } Catch(e) {}}
18. Native JavaScript returns the element object retrieved by ID
function $ (ID) { returnnull : document.getElementById (ID);}
19. Native JavaScript returns browser version content
functionbrowserversion (types) {varother = 1; for(Iinchtypes) { varv = types[i]?Types[i]: i; if(Useragent.indexof (v)! =-1) { varRe =NewRegExp (v + ' (\\/|\\s) ([\\d\\.] +) ', ' IG '); varMatches =re.exec (useragent); varver = matches! =NULL? MATCHES[2]: 0; Other= ver!== 0 && v! = ' Mozilla '? 0: Other; }Else { varver = 0; } eval (' BROWSER. ' + i + ' = Ver '); } browser.other=Other ;}
20. Common method for native JavaScript element display
function $ (ID) { returnnull : document.getElementById (ID);} function display (ID) { var obj = $ (ID); if (obj.style.visibility) { = obj.style.visibility = = ' Visible '? ' Hidden ': ' Visible '; Else { = Obj.style.display = = '? ' None ': '; }}
Native JavaScript skills Collection (11~20)-(Finally I found this article again)