Copy codeThe Code is as follows:
<Script language = "JavaScript" type = "text/JavaScript">
<! --
Var imgObj;
Function checkImg (theURL, winName ){
If (typeof (imgObj) = "object "){
// Whether the image height and width have been obtained
If (imgObj. width! = 0) & (imgObj. height! = 0 ))
// Set the height and width of the pop-up window based on the obtained image height and width, and open the window
// Increment 20 and 30 indicate the interval between the window border and the image.
OpenFullSizeWindow (theURL, winName, ", width =" + (imgObj. width + 20) + ", height =" + (imgObj. height + 30 ));
Else
// Because the Image is dynamically loaded through the Image object, it is impossible to get the Image width and height immediately, so the check is repeated every 100 milliseconds.
SetTimeout ("checkImg ('" + theURL + "', '" + winName + "')", 100)
}
}
Function OpenFullSizeWindow (theURL, winName, features ){
Var aNewWin, sBaseCmd;
// Display parameters
SBaseCmd = "toolbar = no, location = no, status = no, menubar = no, scrollbars = no, resizable = no ,";
// Whether the call is from checkImg
If (features = null | features = ""){
// Create an image object
ImgObj = new Image ();
// Set the image source
ImgObj. src = theURL;
// Start to get the image size
CheckImg (theURL, winName)
}
Else {
// Open the window
ANewWin = window. open (theURL, winName, sBaseCmd + features );
// Focus window
ANewWin. focus ();
}
}
// -->
</Script>
In use, place the above Code in the