IE8 支持 type="file" 吗?

发布于 2024-12-05 07:54:57 字数 674 浏览 0 评论 0 原文

我在显示图像的 php 页面上使用 时遇到 IE8 支持问题,单击该图像会打开文件浏览器以选择要上传的文件。

这在 Firefox 和 Chrome 上工作得很好,我很确定问题来自 及其对 IE8 的支持。 IE8 上的结果是图像没有显示,如果我点击图像位置的白色矩形,什么也不会发生...

这是代码:

<div class="file_wrap">
   <input id="file" type="file" name="file" onchange="sendfile();" />
</div>

和 CSS:

.file_wrap {
   background: url('icon/add.gif');
   overflow:   hidden;
   width:      116px;
   height:     147px;
   cursor:     hand;
}

.file_wrap input {
   opacity:    0;
   font-size:  999px;
   cursor:     hand;
}

也许你们中的一些人之前遇到过这个?

I have a problem of IE8 support with <input type="file"> on a php page displaying an image, which when clicked on opens a file browser to choose a file to upload.

This works fine with Firefox and Chrome and I am pretty sure the problem comes from <input type="file"> and its support with IE8. The result on IE8 is that the image does not get displayed and that if I click on the white rectangle sitting in place of the image nothing happens...

Here is the code:

<div class="file_wrap">
   <input id="file" type="file" name="file" onchange="sendfile();" />
</div>

And the CSS:

.file_wrap {
   background: url('icon/add.gif');
   overflow:   hidden;
   width:      116px;
   height:     147px;
   cursor:     hand;
}

.file_wrap input {
   opacity:    0;
   font-size:  999px;
   cursor:     hand;
}

Maybe some of you guys came across that before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖风昔人 2024-12-12 07:54:57

明确不鼓励使用 元素的自定义样式。

首先,它的默认外观和感觉在不同的浏览器中是完全不同的(你没有提到 Safari,它也使其呈现与其他浏览器非常不同)。仅此一点就很难将其设计得漂亮。

但更重要的是,由于潜在的安全问题,大多数浏览器会主动阻止许多标准 CSS 和 Javascript 操作与 file 元素一起使用。

一些 Javascript 被阻止,以避免恶意脚本拦截或更改文件名和路径。如果允许这种情况,可能发生的后果是相当明显的。

此外,该元素通常只允许使用 CSS 进行相当少量的样式设置。这是因为恶意页面对元素进行样式设计,使其看起来不太像文件元素,从而诱骗用户上传他们不应该上传的文件。

此页面提供了有关该主题的进一步阅读,并提供了成功设计样式的提示。

希望有帮助。

Custom styling of the <input type=file> element is explicitly discouraged.

Firstly, its default look and feel is completely different across the various browsers (you didn't mention Safari, which also renders it very differently from the other browsers). This alone would make it quite hard to style it nicely.

But more importantly, most browsers actively prevent a number of standard CSS and Javascript actions from working with file elements, because of potentital security issues.

Some Javascript is prevented in order to avoid malicious scripts from intercepting or changing the filename and path. The implications of what could happen if this were allowed are fairly obvious.

In addition, the element generally only allows a fairly minimal amount of styling using CSS. This is because malicious pages were styling the element to make it look less like a file element, and thereby tricking users into uploading files that they shouldn't have been uploading.

This page provides further reading on the subject, and gives tips on styling it successfully.

Hope that helps.

夏花。依旧 2024-12-12 07:54:57

与 Chrome 和 Firefox 不同,IE8 在单击稍后包含文件名的文本字段时不会打开“选择文件”对话框,因此这种“黑客”不起作用。

我认为你对此无能为力。如果您想要为文件上传字段自定义样式,请考虑使用基于 Flash 的解决方案,例如 SWFUpload

Unlike in Chrome and Firefox, IE8 doesn't open the "Choose file" dialog when clicking on the text field that will later contain the file name, so this "hack" won't work.

I don't think there is anything you can do about that. If you want custom styling for a file upload field, consider using a Flash-based solution like SWFUpload.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文