Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
JS issue
payal14
Hi,
There is requirement that when user try to enter image size is other then 200x200 or 598x200 user should not be able to save the record.
So i have handled it in JS below is my code.
There is issue that some time wdith and height value return as 0 , so alert get poped up even image size browsed is correct.
Please suggest what should i do?
Code :
function getImgSize11(imgSrc)
{
var newImg = new Image();
alert("Image path::"+imgSrc);
newImg.src=imgSrc;
var height = newImg.height;
var width = newImg.width;
var size_return_val = true;
alert("width" + width + "and height" + height);
if((((width==200)&&(height==200))||((width==598)&&(height==200))) != true)
{
alert("Please select the Banner Image with pixel size 200W x 200H or 598W x 200H");
size_return_val = false;
}
return size_return_val;
}
Find more posts tagged with
Comments
RonaldV
I *think* it could be that the image can not be found at the src-location. Which could result in the height and width returning 0.
Anyway I think this is a scary method to determine the image-size. You are depending on a preview-webserver to return the requested image AND on that the image actually exists where the user says it is.
I would create a call-server for this and run the image-size check on the server. This is much more robust and can check whether the file exists as well.....