Typical JavaScript code for IE operations (recommended)

Source: Internet
Author: User

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.
Copy codeThe Code is as follows:
1. the right mouse button will be completely shielded
Oncontextmenu = "window. event. returnvalue = false"
Table <table oncontextmenu = return (false)> <td> no </table>

2. Cancel selection and prevent Replication
<Bodyonselectstart = "returnfalse">

3. Do not paste
Onpaste = "returnfalse"

4. Prevent Replication
Oncopy = "returnfalse ;"
Oncut = "returnfalse ;"

5. Replace the IE icon in front of the address bar
<Linkrel = "ShortcutIcon" href = "favicon. ico">

6. You can display your icons in the favorites folder.
<Linkrel = "Bookmark" href = "favicon. ico">

7. Disable the Input Method
<Inputstyle = "ime-mode: disabled">

8. Always carry 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
<Noscript> <iframesrc = *. html> </iframe> </noscript>

11. view the webpage source code
<Input type = button value = view the webpage source code onclick = "window. location = 'view-source: '+ 'HTTP: // www.jb51.net/">

12. How to use asp to check whether the visitor has used an agent?
<% IfRequest. ServerVariables ("HTTP_X_FORWARDED_FOR") <> "then
Response. write "<fontcolor = # FF0000> you have passed the proxy server ,"&_
"The real IP address is" & Request. ServerVariables ("HTTP_X_FORWARDED_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, B
Seta = document. all. img1
T = document. all. img1.offsetTop
L = document. all. img1.offsetLeft
Whilea. tagName <> "BODY"
Seta = a. offsetParent
T = t + a. offsetTop
L = l + a. offsetLeft
Wend
Msgbox "top =" & t & chr (13) & "left =" & l, 64, "Get control position"
Endfunction
-->
</Script>

14. The cursor stops at the end of the text box.
<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 = "Maximize"> </object>
<OBJECTid = hh3classid = "clsid: adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAMNAME = "Command" value = "Close"> </OBJECT>
<Inputtype = buttonvalue = minimize onclick = hh1.Click ()>
<Inputtype = buttonvalue = maximized onclick = hh2.Click ()>
<Inputtype = buttonvalue = Disable onclick = hh3.Click ()>
This example applies to IE

17.
<%
'Define some constants for database connection
ConstadOpenForwardOnly = 0' the cursor only views records forward, and does not support paging, Recordset, and BookMark.
ConstadOpenKeyset = 1' indicates the keyset cursor. modifications made by other users to the record are reflected in the record set. However, adding or deleting records by other users is not reflected in the record set. Supports paging, Recordset, and BookMark
ConstadOpenDynamic = 2' the most dynamic cursor function, but the most resource consumption. 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. Supports moving forward or backward
ConstadLockReadOnly = 1' lock type, default, read-only, cannot be modified
ConstadLockPessimistic = 2' lock the record immediately when editing, the safest way
ConstadLockOptimistic = 3' the record set is locked only when the Update method is called, and other operations before this can still change, insert, and delete the current record.
ConstadLockBatchOptimistic = 4' records are not locked when being edited, but changes, inserts, and deletes are completed in the batch processing mode.
Constad1_text = & H0001
ConstadCmdTable = & H0002
%>
18. The webpage will not be cached
HTM webpage
<METAHTTP-EQUIV = "pragma" CONTENT = "no-cache">
<METAHTTP-EQUIV = "Cache-Control" CONTENT = "no-cache, must-revalidate">
<METAHTTP-EQUIV = "expires" CONTENT = "Wed, 26Feb199708: 21: 57GMT">
Or <METAHTTP-EQUIV = "expires" CONTENT = "0">

ASP Web Page
Response. Expires =-1
Response. ExpiresAbsolute = Now ()-1
Response. 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. Get the size of a window
Document. body. clientWidth, document. body. clientHeight

21. How can I determine whether it is a character?
If (/[^-then]/g. test (s) alert ("containing Chinese characters ");
Elsealert ("All characters ");

22. Number of lines of TEXTAREA adaptive text
<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
<Scriptlanguage = javascript>
Functioncc (dd, dadd)
{
// Add error handling.
Vara = newDate (dd)
A = a. valueOf ()
A = a-dadd * 24x60*60*1000
A = newDate ()
Alert (a. getFullYear () + "year" + (a. getMonth () + 1) + "month" + a. getDate () + "day ")
}
Cc ("12/23/2002", 2)
</Script>

24. Which Radio is selected
<HTML> <scriptlanguage = "vbscript">
Functioncheckme ()
Foreachobinradio1
Ifob. checkedthenwindow. alertob. value
Next
Endfunction
</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. servervariables ("") set of the url on this page.
Response. Write "<TABLEborder = 1> <! -- TableHeader --> <TR> <TD> <B> Variables </B> </TD> <B> value </B> </TD> </TR >"
ForeachobinRequest. ServerVariables
Response. write "<TR> <TD>" & ob & "</TD> <TD>" & Request. serverVariables (ob) & "</TD> </TR>"
Next
Response. Write "</TABLE>"

26.
Local ip address <% = request. servervariables ("remote_addr") %>
Server name <% = Request. ServerVariables ("SERVER_NAME") %>
Server IP <% = Request. ServerVariables ("LOCAL_ADDR") %>
Server port <% = Request. ServerVariables ("SERVER_PORT") %>
Server time <% = now %>
IIS version <% = Request. ServerVariables "SERVER_SOFTWARE") %>
Script timeout <% = Server. ScriptTimeout %>
Path of this file <% = 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. Press ENTER to move the cursor 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 = url
If (tim> 200)
{Document. forms [0] ["txt" + B]. value = "link timeout "}
Else
{Document. forms [0] ["txt" + B]. value = "time" + tim/10 + "second "}
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 for the 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 indicator
Move: move mark
Crosshair: Cross logo
E-resize
N-resize
Nw-resize
W-resize
S-resize
Se-resize
Sw-resize

1. There is no local cache, and each time it is automatically refreshed
Response. expires = 0
Response. addHeader "pragma", "no-cache"
Response. addHeader "cache-control", "private"

2. Modify contentType and download gif and other formats
<%
Functiondl (f, n)
Onerrorresumenext
Sets = CreateObject ("Adodb. Stream ")
S. Mode = 3
S. Type = 1
S. Open
S. LoadFromFile (server. mappath (f ))
Iferr. number> 0 then
Response. writeerr. number & ":" & err. description
Else
Response. contentType = "application/x-gzip"
Response. addheader "Content-Disposition:", "attachment; filename =" & n
Response. binarywrite (s. Read (s. size ))
Endif
Endfunction
Calldl ("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. Get the size of a window
Document. body. clientWidth, document. body. clientHeight
Document. body. offsetWidth, document. body. offsetHeight
Sometimes you need to know window. screenTop, window. screenLeft

21. How to determine whether Chinese characters are contained
If (escape (str). indexOf ("% u ")! =-1) alert ("containing Chinese characters ");
Elsealert ("All characters ");

22. Number of lines of TEXTAREA adaptive text
IE5.5 + can use 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)
...{
// 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>

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.