Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

375
Vistas
How to get image size (height & width) and check image using JavaScript on IE?

Are there any JavaScript or jQuery APIs or methods to get the dimensions of an image on the page?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is the solution:

$("#file").change(function (event) {
    var file = this.files[0];
    if (file) {
        var imagefile = file.type;
        var match = ["image/jpeg", "image/png", "image/jpg", "image/tiff"];
        if (!((imagefile == match[0]) || (imagefile == match[1]) || (imagefile ==
            match[2]))) {
            $('#portal_introduce_file').val("");
            this.files = null;
            alert("有効な画像ファイルを選択してください。\n注:許可される画像タイプは jpeg、png、jpg、tiff、pngのみです。")
            return false;
        } else {
            // 画像の寸法を取得するヘルパー
            img = new Image();
            img.src = URL.createObjectURL(file);
            // 次のハンドラーは、画像が正常に読み込まれた後に起動します
            img.onload = function () {
                debugger
                if (img.width <= 750 && img.height <= 170) {
                    $('#portal_introduce_file').val(file.name);
                }
                else {
                    alert('「' + img.width + 'x' + img.height + '」' + 'サイズが無効です。\n' + '画像: 750x170ビクセルで作成');
                    $('#portal_introduce_file').val("");
                }
            };
            img.onerror = function () {
                alert('画像に問題がありました。')
                $('#portal_introduce_file').val("");
            };
        }
    }
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda