Typical JavaScript code for IE operations

Source: Internet
Author: User

This article mainly introduces the classic code of IE operations in JavaScript. If you need some help, please refer to it.

I have been using ajax technology for this time, so I have more opportunities to learn JavaScript knowledge. I have previously collected some JavaScript code on the Internet for IE operations (I can't remember where the idea is, so I won't add the source). It feels useful in the development process, of course, this only applies to IE and FF. Post it for sharing. The Code is as follows: 1. the right-click oncontextmenu = "window. event. returnvalue = false "can be used for Table <table oncontextmenu = return (false)> <td> no </table> 2. cancel selection and prevent copying <bodyonselectstart = "returnfalse"> 3. do not paste onpaste = "returnfalse" 4. prevent copying oncopy = "returnfalse;" oncut = "returnfalse;" 5. replace <linkrel = "Your cuticon" href = "favicon" in front of the IE Address Bar. ico "> 6. <linkrel = "Bookmark" href = "favicon. ico "> 7. disable the input method <inputstyle = "ime-mode: disabled"> 8. always With the framework <scriptlanguage = "javascript"> <! -- If (window = top) top. location. href = "frames.htm"; // --> </script> 9. Prevent frame <SCRIPTLANGUAGE = javascript> <! -- If (top. location! = Self. location) top. location = self. location; // --> </SCRIPT> 10. the webpage cannot be saved as <noscript> <iframesrc = *. html> </iframe> </noscript> 11. view webpage Source Code <input type = button value = view webpage source code onclick = "window. location = 'view-source: '+ 'HTTP: // www.jb51.net/"> 12. how to use asp to check whether the visitor has used a proxy <% ifRequest. serverVariables ("HTTP_X_FORWARDED_FOR") <> "thenresponse. write "<fontcolor = # FF0000> you have passed the proxy server." & _ "the real IP address is" & Request. serverVariables ("HTTP_X_FORW ARDED_FOR ") endif %> 13. obtain the absolute position of the control. // javascript <scriptlanguage = "javascript"> functiongetIE (e )... {vart = e. offsetTop; varl = e. offsetLeft; while (e = e. offsetParent )... {t + = e. offsetTop; l + = e. offsetLeft;} alert ("top =" + t + "left =" + l) ;}</script> // VBScript <scriptlanguage = "VBScript"> <! -- FunctiongetIE () dimt, l, a, bseta = document. all. img1t = document. all. img1.offsetTopl = document. all. img1.offsetLeftwhilea. tagName <> "BODY" seta =. offsetParentt = t +. offsetTopl = l +. offsetLeftwendmsgbox "top =" & t & chr (13) & "left =" & l, 64, "Get control location" endfunction --> </script> 14. the cursor is the last <scriptlanguage = "javascript"> functioncc ()... {vare = event. srcElement; varr = e. createTextRange (); r. moveStart ('character ', e. value. length ); R. collapse (true); r. select () ;}</script> <inputtype = textname = text1value = "123" onfocus = "cc ()"> 15. determine the source of the previous page asp: request. servervariables ("HTTP_REFERER") javascript: document. referrer 16. minimize, maximize, and close the window <objectid = hh1classid = "clsid: ADB880A6-D8FF-11CF-9377-00AA003B7A11 "> <paramname =" Command "value =" Minimize "> </object> <objectid = hh2classid =" clsid: ADB880A6-D8FF-11CF-9377-00AA003B7A11 "> <paramname =" Command "value =" Maximiz E "> </object> <OBJECTid = hh3classid =" clsid: adb880a6-d8ff-11cf-9377-00aa003b7a11 "> <PARAMNAME =" Command "value =" Close "> </OBJECT> <inputtype = buttonvalue = minimal onclick = hh1.Click ()> <inputtype = buttonvalue = maximized onclick = hh2.Click ()> <inputtype = buttonvalue = Disable onclick = hh3.Click ()> This example applies to IE 17. <% 'defines some constant ConstadOpenForwardOnly = 0' for database connection. Only forward browsing records are displayed. pagination, Recordset, and BookMarkConstadOpenKeyset = 1' keyset cursors are not supported, changes made by other users to the record description will be reflected in the record set, but other users add or delete records Records are not reflected in record sets. Supports paging, Recordset, and BookMarkConstadOpenDynamic = 2' with the strongest Dynamic Cursor function, but the most resource-consuming. The added or deleted records modified by the user on the record description will be reflected in the record set. Supports full-featured browsing (ACCESS is not supported ). ConstadOpenStatic = 3' the static cursor is only a snapshot of the data. The changes you make to the record description will not be reflected in the record set. You can move ConstadLockReadOnly = 1' to the front or back of the lock type. The default value is read-only. You cannot modify ConstadLockPessimistic = 2' to lock the record immediately when editing, the safest way is ConstadLockOptimistic = 3'. The record set is locked only when the Update method is called, other operations earlier than this can still change, insert, or delete the current record. The record is not locked when being edited, the change, insert, and delete operations are completed in batch mode. constad1_text = & H0001ConstadCmdTable = & H0002 %> 18. web pages are not cached HTM web pages <METAHTTP-EQUIV = "pragma" CONTENT = "no-cache"> <METAHTTP-EQUIV = "Cache-Control" CONTENT = "no-cache, must-revalidate "> <METAHT TP-EQUIV = "expires" CONTENT = "Wed, 26Feb199708: 21: 57GMT"> or <METAHTTP-EQUIV = "expires" CONTENT = "0"> ASP Web page Response. expires =-1Response. expiresAbsolute = Now ()-1Response. cachecontrol = "no-cache" PHP webpage header ("Expires: Mon, 26Jul199705: 00: 00GMT"); header ("Cache-Control: no-cache, must-revalidate "); header (" Pragma: no-cache "); 19. check whether a string is composed of digits <scriptlanguage = "javascript"> <! -- FunctioncheckNum (str) {returnstr. match (/D/) = null} alert (checkNum ("1232142141") alert (checkNum ("123214214a1") // --> </script> 20. obtain the size of a window document. body. clientWidth, document. body. clientHeight 21. how to determine whether it is a character if (/[^-Hangzhou]/g. test (s) alert ("containing Chinese characters"); elsealert ("All characters"); 22. <textarearows = 1 name = s1 cols = 27 onpropertychange = "this. style. posHeight = this. scrollHeight "> </textarea> 23. the date minus the number of days equals to the second date <scrip Tlanguage = javascript> functioncc (dd, dadd) {// you can add error handling vara = newDate (dd) a =. valueOf () a = a-dadd * 24*60*60 * 1000a = newDate (a) alert (. getFullYear () + "year" + (. getMonth () + 1) + "month" +. getDate () + "day")} cc ("12/23/2002", 2) </script> 24. which Radio <HTML> <scriptlanguage = "vbscript"> functioncheckme () foreachobinradio1ifob is selected. checkedthenwindow. alertob. valuenextendfunction </script> <BODY> <INPUT name = "radio1" type = "radio" value = "style" Checked> Style <INPUT name = "radio1" type = "radio" value = "barcode"> Barcode <INPUT type = "button" value = "check" onclick = "checkme () "> </BODY> </HTML> 25. obtain the request of the url on this page. servervariables ("") set Response. write "<TABLEborder = 1> <! -- TableHeader --> <TR> <TD> <B> Variables </B> </TD> <B> value </B> </TD> </TR> "foreachobinRequest. serverVariablesResponse. write "<TR> <TD>" & ob & "</TD> <TD>" & Request. serverVariables (ob) & "</TD> </TR>" nextResponse. write "</TABLE>" 26. local ip address <% = request. servervariables ("remote_addr") %> server name <% = Request. serverVariables ("SERVER_NAME") %> Server IP address <% = Request. serverVariables ("LOCAL_ADDR") %> server port <% = Request. serverVariables ("SERVER_PO RT ") %> server time <% = now %> IIS version <% = Request. serverVariables "SERVER_SOFTWARE") %> script timeout <% = Server. scriptTimeout %> file path <% = server. mappath (Request. serverVariables ("SCRIPT_NAME") %> server CPU count <% = Request. serverVariables ("NUMBER_OF_PROCESSORS") %> server interpretation engine <% = ScriptEngine & "/" & ScriptEngineMajorVersion &". "& ScriptEngineMinorVersion &". "& ScriptEngineBuildVersion %> Server Operating System <% = Request. serverVariables ("OS") %> 27. the ENTER key allows the light Move to the next input box <input onkeydown = "if (event. keyCode = 13) event. keyCode = 9 "> 28. check the link speed of a Website: Add the following code to the <body> area: <scriptlanguage = javascript> tim = 1 setInterval ("tim ++", 100) B = 1 varautourl = newArray () autourl [1] = "<src =" pic/url.gif "align = absMiddle border = 0> www.njcatv.net" autourl [2] = "javacool.3322.net" autourl [3] = "<src = ""pic/url.gif" align = absMiddle border = 0> www.sina.com.cn "autourl [4] =" www.nuaa.edu.cn "autourl [5] =" <src =" Pic/url.gif "align = absMiddle border = 0> www.cctv.com" functionbutt () {document. write ("<formname = autof>") for (vari = 1; I <autourl. length; I ++) document. write ("<inputtype = textname = txt" + I + "size = 10 value = testing...> = "<Inputtype = textname = url" + I + "size = 40 >=" <inputtype = buttonvalue = GOonclick = window. open (this. form. url "+ I + ". value)> <br/> ") document. write ("<inputtype = submitvalue = Refresh> </form>")} butt () functionauto (url) {document. forms [0] ["url" + B]. value = urlif (tim> 200) {document. forms [0] ["txt" + B]. value = "link timeout"} else {document. forms [0] ["txt" + B]. value = "time" + tim/10 + "seconds"} B ++} functionrun () {for (vari = 1; I <autourl. length; I ++) document. write (" http ://"; + autourl [I] + "')>")} run () </script> 29. various styles of cursor auto: Standard cursor default: Standard arrow hand: hand-shaped cursor wait: Waiting cursor text: I-shaped cursor vertical-text: horizontal I-shaped cursor no-drop: do not drag the cursor not-allowed: Invalid cursor help :? Help cursor all-scroll: triangle direction move: move crosshair: Cross e-resizese-resizesw-resizew-resizes-resizese-resizesw-resize 1. no local cache, automatically refresh response each time. expires = 0response. addHeader "pragma", "no-cache" response. addHeader "cache-control", "private" 2. modify the contentType and download the gif format <% functiondl (f, n) onerrorresumenextsets = CreateObject ("Adodb. stream ") S. mode = 3 s. type = 1 s. opens. loadFromFile (server. mappath (f) iferr. number> 0thenresponse. writeerr. numbe R & ":" & err. descriptionelseresponse. contentType = "application/x-gzip" response. addheader "Content-Disposition:", "attachment; filename =" & nresponse. binarywrite (s. read (s. size) endifendfunctioncalldl ("012922501.gif"," t1.gif ") %> 19. check whether a string is composed of digits <scriptlanguage = "javascript"> <! -- FunctioncheckNum (str)... {return! /D /. test (str)} alert (checkNum ("1232142141") alert (checkNum ("123214214a1") // --> </script> 20. obtain the size of a window document. body. clientWidth, document. body. clientHeightdocument. body. offsetWidth, document. body. offsetHeight sometimes needs to know window. screenTop, window. screenLeft 21. how to determine whether a Chinese character if (escape (str) Is contained ). indexOf ("% u ")! =-1) alert ("containing Chinese characters"); elsealert ("All characters"); 22. the number of lines in the TEXTAREA adaptive text IE5.5 + overflow-y: visible <textarearows = 1 name = s1cols = 27 style = "overflow-y: visible"> </textarea> 23. the date minus the number of days equals to the second date <scriptlanguage = javascript> function cc (dd, dadd )... {// you can add error handling vard = newDate (dd. replace ("-", "/") d. setDate (d. getDate () + dadd) alert (d. getFullYear () + "year" + (d. getMonth () + 1) + "month" + d. getDate () + "day")} cc ("2002-2-28", 2) </script>

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.