Today, Gonten found a piece of useful code in a CMS template to share with you. Some web pages are often seen, because the images are too large to control the image size, resulting in page dislocation, or some images cannot be seen. The following code will solve this problem.
The Code is as follows:
<Script type = "text/javascript">
Function ImgSize (){
Var obj = document. getElementById ("Content"). getElementsByTagName ("img ");
If (! Obj) obj = document. images;
For (I = 0; I <obj. length; I ++ ){
If (obj ){
If (obj [I]. width> 666 ){
Obj [I]. width = 666;
Obj [I]. style. width = 666;
Obj [I]. title = "click to view the large image ";
Obj [I]. style. cursor = "pointer ";
Obj [I]. border = 0;
Obj [I]. onclick = function (e) {window. open (this. src );}
}
}
}
}
ImgSize ()
</Script>
The Code shows that not only can the image with an ID of more than 666 pixels under the content be reduced to 600 pixels, but also the link address of the image is automatically added to the image, the system prompts "click to view the big image ". The 666 value can be changed to another suitable size, which is very convenient.