Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35780

Re: Image load problem: OK in my Win 7, not in either Win10

Newsgroups comp.lang.javascript
Subject Re: Image load problem: OK in my Win 7, not in either Win10
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <f38f3d44-7c43-4483-a82c-fb0159fd941b@googlegroups.com> <8b16a9d8-6d22-47b8-8e2d-13595c1fad71@googlegroups.com>
Date 2018-10-14 11:11 +0200
Message-ID <XnsA97B71D84B898eejj99@194.109.6.166> (permalink)

Show all headers | View raw


"Michael Haufe (TNO)" <tno@thenewobjective.com> wrote on 14 Oct 2018 in
comp.lang.javascript: 

> Dr J R Stockton wrote:
>> I have the following script fragment in a local HTML page.
>> FM is a <form>, IM is an unsized <img>.  IM and a textarea
>> are position:absolute within a position:relative <div>.
>> The value of DocName names a local .PNG file of about 5kB,
>> image 640*800px.
>> 
>> Function NewDoc is called by <body onload="...">, and
>> not before.
>> 
>> In my Win7 PC, Wide and High get the hoped-for values
>> 640 & 800 and function Draw shows the image - OK.
>> 
>> In my Win10 PCs, Wide and High are each about 35, and
>> no part of the image appears - NOT GOOD.  Firefox logs
>> no detected errors.
>> 
>> I intend to replace, but not tonight, the setTimeout
>> with a setInterval of about 0.1 seconds, which will
>> repeatedly call code to test the .complete property
>> of the image element and, when that is true will
>> end the timer and call function Draw.
>> 
>> Any (useful) comment?
>> 
>> 
>> <script type="text/javascript">
>> var IM, Form0, Wide, High // Globals
>> 
>> function NewDoc() {  // Just read the form and wait a bit
>>   Form0 = document.getElementById('FM'),
>>   IM = document.getElementById("IM")
>>   IM.src = Form0.DocName.value          // Get and show the Form
>>   setTimeout(Next, 1500)          // Short delay needed here
>>   }
>> 
>> function Next() { // Just show and remember original image details
>>   Form0.Iwh.value = Wide = IM.width
>>   Form0.Iht.value = High = IM.height
>>   Draw() }
> 
> My first comment is that images have 'onload' and 'onerror' methods you
> can override. This will eliminate the need for the setTimeout: 
> 
> img.onload = next
> img.onerror = fail
> 
> Second, try using the .elements property of the form:
> 
> myForm.elements.inputName
> myForm.elements["input-name"]
> 
> 
> Third, you can access the original image size by using the
> .naturalHeight and .naturalWidth properties. 
> 
> Fourth, you should use the JavaScript coding conventions. PascalCase is
> reserved for classes and constructor functions. 

John, you could play with this:

==============
<body>
<script>
  'use strict';
  document.body.onload = () => {
    const myDiv = document.createElement("DIV");
    document.body.appendChild(myDiv);
  
    const myImg = document.createElement("IMG");
    myImg.setAttribute("src", "abcde.jpg");
    document.body.appendChild(myImg);
  
    myImg.onload = () => myDiv.innerHTML = myImg.naturalHeight;
  };
</script>
==============




-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Image load problem: OK in my Win 7, not in either Win10 Dr J R Stockton <J.R.Stockton@physics.org> - 2018-10-13 14:29 -0700
  Re: Image load problem: OK in my Win 7, not in either Win10 "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-10-13 20:40 -0700
    Re: Image load problem: OK in my Win 7, not in either Win10 "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-10-14 11:11 +0200
    Re: Image load problem: OK in my Win 7, not in either Win10 John G Harris <niam@jghnorth.org.uk.invalid> - 2018-10-14 11:18 +0100
      Re: Image load problem: OK in my Win 7, not in either Win10 "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-10-14 22:06 -0700
    Re: Image load problem: OK in my Win 7, not in either Win10 Dr J R Stockton <J.R.Stockton@physics.org> - 2018-10-14 06:01 -0700
      Re: Image load problem: OK in my Win 7, not in either Win10 "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-10-14 15:29 +0200
      Re: Image load problem: OK in my Win 7, not in either Win10 "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-10-14 21:42 -0700
        Re: Image load problem: OK in my Win 7, not in either Win10 Dr J R Stockton <J.R.Stockton@physics.org> - 2018-10-15 05:02 -0700
          Re: Image load problem: OK in my Win 7, not in either Win10 "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-10-15 16:06 +0200
            Re: Image load problem: OK in my Win 7, not in either Win10 Dr J R Stockton <J.R.Stockton@physics.org> - 2018-10-15 15:43 -0700
          Re: Image load problem: OK in my Win 7, not in either Win10 "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-10-16 02:55 -0700
            Re: Image load problem: OK in my Win 7, not in either Win10 Dr J R Stockton <J.R.Stockton@physics.org> - 2018-10-16 05:00 -0700

csiph-web