Below is a good example.
CopyCode The Code is as follows: function formatimg2 (content)
Dim re
Set Re = new Regexp
Re. ignorecase = true
Re. Global = true
Re. pattern = "(SCRIPT )"
Content = Re. Replace (content, "script ")
Re. pattern = "] * SRC (= |) (. [^>] *)>"
Content = Re. replace (content, " ")
Set Re = nothing
Formatimg = content
End Function
The preceding error is that the width and height of the image do not exist.Copy codeThe Code is as follows: function getphoto (strhtml)
Dim objregexp, match, matches
Set objregexp = new Regexp
Objregexp. ignorecase = true
Objregexp. Global = true
Objregexp. pattern = " "
TP = ""
Set matches = objregexp. Execute (strhtml)
For each match in matches
TP = TP & Match. Value
Exit
Next
Getphoto = TP
Set objregexp = nothing
End Function
The following code scales the image proportionally.Copy codeThe Code is as follows: function resizeimage (imageid, limitwidth, limitheight)
{
VaR image = new image ();
Image. src = imageid. SRC;
If (image. width <= 0 & image. height <= 0) return;
If (image. width/image. Height> = limitwidth/limitheight)
{
If (image. width> limitwidth)
{
Imageid. width = limitwidth;
Imageid. Height = (image. Height * limitwidth)/image. width;
}
}
Else if (image. Height> limitheight)
{
Imageid. Height = limitheight;
Imageid. width = (image. Width * limitheight)/image. height;
}
If (imageid. parentelement. tagname! = "")
{
Imageid. onclick = function () {window. Open (this. SRC );}
Imageid. style. cursor = "hand ";
}
}
Window. onload = initimages;
Function initimages ()
{
// Constrain width and height of the image
VaR maxwidth = 100;
VaR maxheight = 100;
VaR IMGs = Document. getelementsbytagname ("IMG ");
For (VAR I = 0; I {
VaR IMG = IMGs;
If (IMG. width> maxwidth | IMG. Height> maxheight)
Resizeimage (IMG, maxwidth, maxheight );
}
}