Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #33365
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Instead of <iframe onload=... |
| Date | 2017-05-22 03:27 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <7307682.T7Z3S40VBb@PointedEars.de> (permalink) |
| References | <5638b17e-4ab2-4605-ac32-b399ddcfa099@googlegroups.com> <ofmrnu$sc9$1@news.albasani.net> <b06552ca-cd04-4314-8dea-76a7630b4058@googlegroups.com> <hogR$$KPILIZFwpJ@invalid.uk.co.demon.merlyn.invalid> |
Dr J R Stockton wrote:
> function Ink(Sauce, DefaultHeight) { var Fram
> […]
> Fram.onload = Inky(Fram, DefaultHeight)
^^^^^
> […]
> function Inky(Ifr, ExHi) {
> // Autosize works in Firefox and MS IE (Edge?), else use ExHi
> setTimeout(function() { Procrustes(Ifr, ExHi) } , 500) }
[Unusual, highly questionable code style aside:]
JFTR, this is a common mistake. This way the function Inky() would be
called *before* the assignment to the “onload” property, and the “onload”
property would be assigned the “undefined” value when either the “null”
value or a reference to a Function instance is expected. Such an assignment
would result in a runtime error in earlier versions of Internet Explorer;
later versions might have a setter for that property to ignore it and to
keep the default “null” property value.
It is therefore unsurprising to me that the timeout delay would have to be
set that high (500 ms) as calling Inky() does _not_ correspond with loading
the iframe document.
Perhaps the following was sought for instead:
iframe.onload = function () {
inky(this, defaultHeight);
};
However, usually one would wrap the iframe object into a custom object with
appropriate initialization and methods instead of global functions (OOP:
encapsulation, information hiding). For example (quick hack):
/* @namespace */
var JRS = (function () {
"use strict";
/* @constructor */
function _IframeWidget (target, source)
{
if (!(this instanceof _IframeWidget))
{
return new _IframeWidget(target, source);
}
this.target = target || document.createElement("iframe");
Object.assign(this.target.style, {
border: "2px solid red",
width: "100%",
margin: "0.5ex 0",
background: "#FFE"
});
this.target.onload = function () {
this.procrustes();
}.bind(this);
if (!target) document.body.appendChild(this.target);
this.target.src = source;
}
Object.assign(_IFrameWidget.prototype, {
/* @memberOf JRS.IFrameWidget.prototype */
defaultHeight: …,
procrustes: function (exHi) {
// … this.target.contentDocument …
}
});
Object.defineProperty(_IFrameWidget.prototype, "constructor", {
/* @memberOf JRS.IFrameWidget.prototype */
value: _IFrameWidget
});
return {
/* @memberOf JRS */
IframeWidget: _IFrameWidget
};
}());
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Instead of iframe onload? Dr J R Stockton <J.R.Stockton@physics.org> - 2017-05-18 05:40 -0700
Re: Instead of iframe onload? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-18 15:07 +0200
Re: Instead of iframe onload? Dr J R Stockton <J.R.Stockton@physics.org> - 2017-05-18 08:11 -0700
Re: Instead of iframe onload? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-18 18:09 +0200
Re: Instead of iframe onload? Andrew Poulos <ap_prog@hotmail.com> - 2017-05-19 12:36 +1000
Re: Instead of iframe onload? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-19 09:15 +0200
Re: Instead of iframe onload? Andrew Poulos <ap_prog@hotmail.com> - 2017-05-19 18:12 +1000
Re: Instead of iframe onload? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-19 11:47 +0200
Re: Instead of iframe onload? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2017-05-19 02:44 -0700
Re: Instead of iframe onload? Martin Honnen <martin.honnen@gmx.de> - 2017-05-19 15:25 +0200
Re: Instead of iframe onload? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-19 18:11 +0200
Re: Instead of iframe onload? Dr J R Stockton <J.R.Stockton@physics.org> - 2017-05-19 14:30 -0700
Instead of <iframe onload=... Dr J R Stockton <reply1700@merlyn.demon.co.uk.invalid> - 2017-05-20 22:15 +0100
Re: Instead of <iframe onload=... Stefan Weiss <krewecherl@gmail.com> - 2017-05-21 02:10 +0200
Re: Instead of <iframe onload=... Dr J R Stockton <J.R.Stockton@physics.org> - 2017-05-21 11:46 -0700
Re: Instead of <iframe onload=... Dr J R Stockton <reply1700@merlyn.demon.co.uk.invalid> - 2017-05-24 23:18 +0100
Re: Instead of <iframe onload=... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-21 23:22 +0200
Re: Instead of <iframe onload=... Stefan Weiss <krewecherl@gmail.com> - 2017-05-22 00:39 +0200
Re: Instead of <iframe onload=... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-22 01:38 +0200
Re: Instead of <iframe onload=... Stefan Weiss <krewecherl@gmail.com> - 2017-05-22 02:19 +0200
Re: Instead of <iframe onload=... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-22 02:35 +0200
Re: Instead of <iframe onload=... Stefan Weiss <krewecherl@gmail.com> - 2017-05-22 12:54 +0200
Re: Instead of <iframe onload=... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-22 15:37 +0200
Re: Instead of <iframe onload=... Stefan Weiss <krewecherl@gmail.com> - 2017-05-22 18:23 +0200
Re: Instead of <iframe onload=... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-23 14:15 +0200
Re: Instead of <iframe onload=... Stefan Weiss <krewecherl@gmail.com> - 2017-05-23 15:56 +0200
Re: Instead of <iframe onload=... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-23 18:41 +0200
Re: Instead of <iframe onload=... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-22 03:27 +0200
csiph-web