JavaScript Classic code for IE operations (recommended) _javascript tips

Source: Internet
Author: User
Tags error handling getdate servervariables server port

This period of time has been using AJAX technology to do things, so there will be more opportunities to learn JavaScript knowledge. Earlier on the internet to collect some about the JavaScript of IE operation code (specifically where cope, so the source is not added), feeling in the development process is very useful, of course, only applicable to IE,FF will have problems. Now stick it out and share it.

Copy Code code as follows:

1. Will completely screen the right mouse button
oncontextmenu= "Window.event.returnvalue=false"
Available for table<table Oncontextmenu=return (false) ><td>no</table>

2. Deselect, prevent replication
<bodyonselectstart= "Returnfalse" >

3. No pasting
Onpaste= "Returnfalse"

4. Prevention of duplication
Oncopy= "Returnfalse;"
Oncut= "Returnfalse;"

5.IE Address bar in front of your own icon
<linkrel= "Shortcuticon" href= "Favicon.ico" >

6. You can display your icon in the Favorites folder
<linkrel= "Bookmark" href= "Favicon.ico" >

7. Close the Input method
<inputstyle= "Ime-mode:disabled" >

8. Always with the frame
<scriptlanguage= "JavaScript" >
<!--
if (window==top) top.location.href= "frames.htm";
-->
</script>

9. Prevent a person from being frame
<SCRIPTLANGUAGE=javascript>
<!--
if (top.location!=self.location) top.location=self.location;
-->
</SCRIPT>

10. Web pages will not be saved as
<noscript><iframesrc=*.html></iframe></noscript>

11. View Web page source code
<input type=button value= View Web page source code onclick= "window.location= ' view-source: ' + ' http://www.jb51.net/' >

12. How to use the ASP means to check whether the visitor used the agent
<%ifrequest.servervariables ("http_x_forwarded_for") <> "" Then
Response.Write "<fontcolor= #FF0000 > You have passed the proxy server," &_
"True IP is" &request.servervariables ("Http_x_forwarded_for")
endif
%>

13. Get 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 & "left=" &l,64, "get position of control"
Endfunction
-->
</script>

14. Cursor is stopped at the end of text box text
<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. Determining the origin of the previous page
Asp:
Request.ServerVariables ("Http_referer")
Javascript:
Document.referrer

16. Minimize, maximize, close windows
<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= maximize ONCLICK=HH2. Click () >
<inputtype=buttonvalue= closes the onclick=hh3. Click () >
This example applies to IE


<%
Define some constants for database connections
Constadopenforwardonly=0 ' cursors navigate only records forward, not paging, Recordset, BookMark
Constadopenkeyset=1 ' keyset cursors, changes made to records by other users will be reflected in the recordset, but other users adding or deleting records will not be reflected in the recordset. Supports paging, Recordset, BookMark
constadopendynamic=2 ' Dynamic cursors are the most powerful, but also the most expensive sources. User changes to the record, add or delete records will be reflected in the recordset. Supports full feature browsing (not supported by Access).
constadopenstatic=3 ' static cursors, just a snapshot of the data, changes that the user makes to the record, adding or deleting records are not reflected in the recordset. Supports moving the
Constadlockreadonly=1 ' lock type Forward or backward, default, read-only, cannot make any changes
constadlockpessimistic=2 ' lock records immediately when editing, the safest way to
Constadlockoptimistic=3 ' The recordset is locked only when the Update method is invoked, while other previous operations can still make changes, inserts, and deletions to the current record, such as
constadlockbatchoptimistic= 4 ' records are not locked while editing, while changes, inserts, and deletions are completed in batch mode by
constadcmdtext=&h0001
constadcmdtable=&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"
<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 Web page
Header ("Expires:mon,26jul199705:00:00gmt");
Header ("Cache-control:no-cache,must-revalidate");
Header ("Pragma:no-cache");

19. Check whether a string of strings is all composed of numbers
<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 to judge whether it is a character
if (/[^-ÿ]/g.test (s)) alert ("contains Chinese characters");
Elsealert ("all characters");

22.TEXTAREA the number of adaptive lines of text
<textarearows=1 name=s1 cols=27 onpropertychange= "This.style.posheight=this.scrollheight" >
</textarea>

23. Date minus days equals second date
<scriptlanguage=javascript>
FUNCTIONCC (Dd,dadd)
{
You can add error handling
Vara=newdate (DD)
A=a.valueof ()
a=a-dadd*24*60*60*1000
A=newdate (a)
Alert (a.getfullyear () + "year" + (A.getmonth () +1) + "month" +a.getdate () + "Day")
}
CC ("12/23/2002", 2)
</script>

24. Which radio was chosen
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. Get the Request.ServerVariables ("") Collection
Response.Write <TABLEborder=1><!--tableheader--> for this page URL <tr><td><b>variables</b></td><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.
Native Ip<%=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 Time <%=Server.ScriptTimeout%>
This file path <%=server.mappath (Request.ServerVariables ("Script_name"))%>
Server CPU number <%=request.servervariables ("Number_of_processors")%>
Server Interpretation engine <%=ScriptEngine& "& ScriptEngineMajorVersion &". "& ScriptEngineMinorVersion &". & scriptenginebuildversion%>
Server operating system <%=request.servervariables ("OS")%>

The 27.ENTER key allows the cursor to move to the next input box
<input onkeydown= "if (event.keycode==13) event.keycode=9" >

28. Detect 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=10value= test ... >=" <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+ "Seconds"}
b++
}
Functionrun () {for (vari=1;i<autourl.length;i++) document.write ("http://"; +autourl[ i]+ "') >")}
Run () </script>

29. Various styles of cursors
Auto: Standard cursor
Default: Standard arrow
Hand: hand-shaped cursor
Wait: Waiting for cursor
Text:i-shaped cursor
Vertical-text: Horizontal i-type cursor
No-drop: Non-drag cursor
Not-allowed: Invalid cursor
Help:? Helper cursors
All-scroll: Triangle directional Sign
Move: Moving the label
Crosshair: Cross Mark
E-resize
N-resize
Nw-resize
W-resize
S-resize
Se-resize
Sw-resize

1. No cache locally, automatic refresh every time
Response.expires=0
Response.AddHeader "Pragma", "No-cache"
Response.AddHeader "Cache-control", "private"

2. Modify contenttype and download GIF format
<%
Functiondl (F,n)
Onerrorresumenext
Sets=createobject ("ADODB.stream")
S.mode=3
S.type=1
S.open
S.loadfromfile (Server.MapPath (f))
Iferr.number>0then
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 of strings is all composed of numbers
<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 judge whether to contain Chinese characters
if (Escape (str). IndexOf ("%u")!=-1) alert ("contains Chinese characters");
Elsealert ("all characters");

22.TEXTAREA the number of adaptive lines of text
ie5.5+ can use overflow-y:visible
<textarearows=1name=s1cols=27style= "Overflow-y:visible" >
</textarea>

23. Date minus days equals 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.