One of my half-month code summaries (TIPS, code)

Source: Internet
Author: User
I. Common HTTP checking functions:

Functions:

1. Check the website connection code entered by the user (if it starts with a non-http: //, an HTTP header is automatically added)
2: regardless of the Path entered by the user, only show the main site URL (such as http://blog.sina.com.cn/myblog/u/3554345.htm only show http://blog.sina.com.cn /)

Public String checkhttp (string HTTP) // check HTTP
{


If (! (HTTP = "original ")&&! (HTTP = "Vote ")&&! (HTTP = "") // if it is not --- original, vote, or empty
{
If (HTTP. indexof ("http: //")>-1) // determine whether the HTTP header is included
{
If (HTTP. substring (7, HTTP. Length-7). indexof ("/")>-1) // Delete the "/" after the URL expires when the header is included
{
HTTP = http. substring (0, HTTP. substring (7). indexof ("/") + 8 );
}
}
Else
{

If (HTTP. indexof ("/")>-1) // No HTTP Header
{
HTTP = (HTTP. substring (0, HTTP. indexof ("/") + 1). insert (0, "http ://");
}
}
}
Else
{
Return HTTP;
}
Return HTTP;

}

Ii. Image Scaling Method

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
<Script language = "JavaScript">
Function chang_img (IMG, maxwidth, maxheight ){
VaR image = new image ();
Image = IMG;
If (image. width/image. Height> = maxwidth/maxheight)
{
If (image. width> maxwidth)
{
IMG. width = maxwidth;
IMG. Height = maxwidth * image. Height/maxheight;
}
Else
{
IMG. width = image. width;
IMG. Height = image. height;
}
}
Else
{
If (image. Height> maxheight)
{
IMG. width = maxheight * image. width/image. height;
IMG. Height = image. height;
}
Else
{
IMG. width = image. width;
IMG. Height = image. height;
}
}
} </SCRIPT>
</Head>

<Body>


</Body>
</Html>
Solve the problem: Normally, when we are not sure about the image size, we need to take the form of a scaling chart when determining the size format of the image output,
If the image size is hard to be displayed, two kinds of errors will occur: one is severely distorted after the image is scaled, and the other is seen in only a part of the small area.

The above code is used to determine the scaling ratio and structure after calculation and height.

The IMG variable is the referenced image "object" and can be passed to this variable through this
Maxwidth: the actual image display width after scaling
Maxheight: the actual image height to be scaled

Haha, no distortion

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.