img onload 在 IE7 中无法正常工作 [英] img onload doesn't work well in IE7

查看:19
本文介绍了img onload 在 IE7 中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 web 应用中有一个 img 标签,它使用 onload 处理程序来调整图像大小:

I have an img tag in my webapp that uses the onload handler to resize the image:

<img onLoad="SizeImage(this);" src="foo" >

这在 Firefox 3 中工作正常,但在 IE7 中失败,因为由于某种原因传递给 SizeImage() 函数的图像对象的宽度和高度为 0 -- 也许 IE 调用了该函数在它完成加载之前?.在研究这一点时,我发现其他人在使用 IE 时也遇到了同样的问题.我还发现这不是有效的 HTML 4.这是我们的 doctype,所以我不知道它是否有效:

This works fine in Firefox 3, but fails in IE7 because the image object being passed to the SizeImage() function has a width and height of 0 for some reason -- maybe IE calls the function before it finishes loading?. In researching this, I have discovered that other people have had this same problem with IE. I have also discovered that this isn't valid HTML 4. This is our doctype, so I don't know if it's valid or not:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

是否有一种合理的解决方案可以在加载图像时调整其大小,最好是符合标准的解决方案?该图像用于用户上传他们自己的照片,几乎可以是任何尺寸,我们希望以最大 150x150 显示它.如果您的解决方案是在上传时调整图像服务器端的大小,我知道这是正确的解决方案,但我被禁止实施它:( 必须在客户端完成,并且必须在显示上完成.

Is there a reasonable solution for resizing an image as it is loaded, preferably one that is standards-compliant? The image is being used for the user to upload a photo of themselves, which can be nearly any size, and we want to display it at a maximum of 150x150. If your solution is to resize the image server-side on upload, I know that is the correct solution, but I am forbidden from implementing it :( It must be done client side, and it must be done on display.

谢谢.

编辑:由于我们应用程序的结构,在文档的 onload 中运行此脚本是不切实际的(几乎不可能).我只能合理地编辑图像标签和它附近的代码(例如,我可以在它的正下方添加一个

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆