Several js methods about HTML

Source: Internet
Author: User

// Add to the favorite function addBookmark (title) {var url = parent. location. href; if (window. sidebar) {window. sidebar. addPanel (title, url, "");} else if (document. all) {window. external. addFavorite (url, title);} else if (window. opera & window. print) {return true ;}/// set the Home Page function setHome (obj, vrl) {try {obj. style. behavior = 'url (# default # homepage) '; obj. setHomePage (vrl);} catch (e) {if (window. netscape) {try {netsca Pe. security. PrivilegeManager. enablePrivilege ("UniversalXPConnect");} catch (e) {alert ("Sorry! Your browser does not support direct homepage setting. Enter "about: config" in the address bar of your browser and press enter to [signed. applets. codebase_principal_support] is set to "true". Click "add to Favorites" and ignore the security prompt. The setting is successful. ");} Var prefs = Components. classes ['@ mozilla.org/preferences-service%1'%.getservice (Components. interfaces. nsIPrefBranch); prefs. setCharPref ('browser. startup. homepage ', vrl) ;}} var MY = new Object (); // The Cookie reading function MY. cookie = {set: function (name, value, expires, path, domain) {if (typeof expires = "undefined") {expires = new Date (). getTime () + 24*3600*1000);} document. cookie = name + "=" + decodeURI (value) + (exp Ires )? "; Expires =" + expires. toGMTString (): "") + (path )? "; Path =" + path: "; path =/") + (domain )? "; Domain =" + domain: "") ;}, get: function (name) {var arr = document. cookie. match (new RegExp ("(^ |)" + name + "= ([^;] *) (; | $)"); if (arr! = Null) {return decodeURIComponent (arr [2]);} return null ;}, clear: function (name, path, domain) {if (this. get (name) {document. cookie = name + "=" + (path )? "; Path =" + path: "; path =/") + (domain )? "; Domain =" + domain: "") + "; expires = Fri, 02-Jan-1970 00:00:00 GMT ";}}}; // function limitImage (ImgD, areaWidth, areaHeight) {var flag = false; if (! AreaWidth) {areaWidth = 600; // The width of the image area.} If (! AreaWidth) {areaHeight = 450; // The height of the image area.} Var image = new Image (); try {image. src = ImgD. src; if (image. width> 0 & image. height> 0) {flag = true; if (image. width/image. height> = areaWidth/areaHeight) {if (image. width> areaWidth) {ImgD. width = areaWidth; ImgD. height = (image. height * areaWidth)/image. width;} else {ImgD. width = image. width; ImgD. height = image. height ;}} else {if (image. height> areaHeight) {ImgD. height = areaHeight; ImgD. width = (image. wid Th * areaHeight)/image. height;} else {ImgD. width = image. width; ImgD. height = image. height ;}}} catch (e) {// nothing }}// copy to clipboard function copyCodes (ele) {if (copy2Clipboard (ele )! = False) {alert ("the generated code has been copied to the clipboard. You can use Ctrl + V to paste it to the desired place! ") ;}}// Copy to clipboard function copyCode () {var testCode =" "; testCode + = document. title + ''+ this. location. href; if (copy2Clipboard (testCode )! = False) {alert ("the generated code has been copied to the clipboard. You can use Ctrl + V to paste it to the desired place! ") ;}} Copy2Clipboard = function (txt) {if (window. clipboardData) {window. clipboardData. clearData (); window. clipboardData. setData ("Text", txt);} else if (navigator. userAgent. indexOf ("Opera ")! =-1) {window. location = txt;} else if (window. netscape) {try {netscape. security. privilegeManager. enablePrivilege ("UniversalXPConnect");} catch (e) {alert ("your firefox security restrictions limit you to perform clipboard operations. Open 'about: config' and set signed. applets. codebase_principal_support 'is set to true and then try again. The relative path is the firefox root directory/greprefs/all. js "); return false;} var clip = Components. classes ['@ mozilla.org/widget/clipboard1_1').createinstance (Components. interfaces. NsIClipboard); if (! Clip) return; var trans = Components. classes ['@ mozilla.org/widget/transferable1_1'assist.createinstance (Components. interfaces. nsITransferable); if (! Trans) return; trans. addDataFlavor ('text/unicode '); var str = new Object (); var len = new Object (); var str = Components. classes ["@ mozilla.org/supports-string1_1"]. createInstance (Components. interfaces. nsISupportsString); var copytext = txt; str. data = copytext; trans. setTransferData ("text/unicode", str, copytext. length * 2); var clipid = Components. interfaces. nsIClipboard; if (! Clip) return false; clip. setData (trans, null, clipid. kGlobalClipboard) ;}}/*** get url parameter */function getUrlParam (paramName) {var returnVal = ""; try {var paramUrl = window. location. search; // processing length if (paramUrl. length> 0) {paramUrl = paramUrl. substring (1, paramUrl. length); var paramUrlArray = paramUrl. split ("&"); for (var I = 0; I
 
  

Related Article

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.