ASP FAQs and Answers (11)

Source: Internet
Author: User
FAQ | Common JavaScript function for problems
//=========================================
Input data validation
Checking for null values
function Funcheckempty (m_text) {
var strtmp=m_text
if (strtmp = null | | strtmp = = "") {
return False
}
return True
}



Check the length of the content
function Funtextlencheck (m_text) {
var strtext=m_text
for (i=0;i<=strtext.length-1;i++) {
if (Strtext.charcodeat (i) >=256) {
Return Strtext.length * 2
}
}
Return strtext.length
}


Inspection length
function Funchecklen (m_len,m_text) {
if (Funtextlencheck (m_text) > M_len) {
return False
}
return True
}

Test is a number
function Funchecknumber (m_text) {
var strtmp=m_text
if (isNaN (strtmp)) {
return False
}
return True
}


Whether the date of inspection is legal
function Funcheckdate (m_year,m_month,m_day) {
Get the maximum date according to the month first
var maxday
if (m_month==2) {
Maxday=28
if (m_year% 4 ==0) {
maxday=29
}
} else {
if (m_month<=7) {
if (m_month% 2 ==0) {
Maxday=30
}else{
Maxday=31
}
}else{
if (m_month% 2 ==0) {
Maxday=31
}else{
Maxday=30
}
}
}
if (m_day>maxday) {
return False
}
return True
}

Read cookies information
function GetCookie (strcookname) {
var arvcookies=document.cookie.split (";")
for (var i=0;i< arvcookies.length; i++) {
var arvonecookie=arvcookies[i].split ("=")
if (Strcookname==arvonecookie[0]) {
Return unescape (Arvonecookie[1])
}
}
Return ""
}

To replace an illegal character in a string
function Replace_text (Text) {
var strtmp=text
Strtmp=strtmp.replace ("@", "@")
Strtmp=strtmp.replace ("?", "? ")
Strtmp=strtmp.replace ("&", "&")
Strtmp=strtmp.replace ("'", "" ")
Strtmp=strtmp.replace ("<", "" ")
Strtmp=strtmp.replace (">", "")
Return strtmp

}


function Check_password (text) {
var strtmp=text
if (Strtmp.indexof ("") >-1) {
Return "'"
}
if (Strtmp.indexof ("?") &GT;-1) {
Return "?"
}
if (Strtmp.indexof ("&") >-1) {
Return "&"
}
if (Strtmp.indexof ("<") >-1) {
Return "<"
}
if (Strtmp.indexof (">") >-1) {
Return ">"
}
Return ""

}


function Check_url (text) {
var strtmp=text
if (Strtmp.indexof ("") >-1) {
return False
}
return True
}

Focus Control
function Document.onkeydown () {
var e = event.srcelement;
if (Event.keycode = && e.tagname = "INPUT" && e.type = = "Text") {
Event.keycode = 9;
}

}





<% Response.Write "
1.oncontextmenu= "Window.event.returnvalue=false" will completely mask the right mouse button
<tableborderoncontextmenu=return (False) ><td>no</table> available for table
2.<bodyonselectstart= "Returnfalse" > Deselect, Prevent replication
3.onpaste= "Returnfalse" is not allowed to paste
4.oncopy= "Returnfalse;" Oncut= "Returnfalse;" Prevent replication
5.<linkrel= "Shortcuticon" href= "Favicon.ico" >ie address bar in front of its own icon
6.<linkrel= "Bookmark" href= "Favicon.ico" > can display your icon in a Favorites folder
7.<inputstyle= "ime-mode:disabled" > Close IME
8. Always with the frame
<scriptlanguage= "JavaScript" ><!--
if (window==top) top.location.href= "frames.htm";//frames.htm for frames page
--></script>
9. Prevent a person from being frame
<scriptlanguage=javascript><!--
if (top.location!=self.location) top.location=self.location;
--></script>
10.<noscript><iframesrc=*.html></iframe></noscript> Web pages will not be saved as
11.<inputtype=buttonvalue= View Web page source code
onclick= "Window.location=view-source:+ http://www.csdn.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= #ff000



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.