Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #24136 > unrolled thread
| Started by | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| First post | 2014-05-12 14:38 +1000 |
| Last post | 2014-05-14 09:57 -0700 |
| Articles | 14 — 6 participants |
Back to article view | Back to comp.lang.javascript
intercept an alert Andrew Poulos <ap_prog@hotmail.com> - 2014-05-12 14:38 +1000
Re: intercept an alert Andrew Poulos <ap_prog@hotmail.com> - 2014-05-12 15:35 +1000
Re: intercept an alert Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-12 11:32 +0200
Re: intercept an alert Simon Lewis <simonlewis2001@gmail.com> - 2014-05-12 12:29 +0200
Re: intercept an alert Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-12 13:30 +0200
Re: intercept an alert "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-05-12 14:54 +0200
Re: intercept an alert "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-05-12 15:36 +0200
Re: intercept an alert Simon Lewis <simonlewis2001@gmail.com> - 2014-05-12 15:40 +0200
Re: intercept an alert Simon Lewis <simonlewis2001@gmail.com> - 2014-05-12 15:43 +0200
Re: intercept an alert "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-05-12 16:19 +0200
Re: intercept an alert Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-12 19:35 +0200
Re: intercept an alert garrett.smith@acxiom.com - 2014-05-14 09:57 -0700
Re: intercept an alert Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-05-13 18:00 +0100
Re: intercept an alert garrett.smith@acxiom.com - 2014-05-14 09:57 -0700
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-05-12 14:38 +1000 |
| Subject | intercept an alert |
| Message-ID | <862dneogqrcsze3OnZ2dnUVZ_gCdnZ2d@westnet.com.au> |
I've been using a 3rd party web platform to build a web site.
The platform can display its own alerts.
I need to prevent one of the alerts but as I have no access to the code
that is generating the alert so I'm wondering if there's a way to
intercept it.
If its the message in question then it is to be prevented from
displaying otherwise the alert displays as "normal".
I thought of doing
window.alert = function(msg){
if (msg.indexOf('Is empty') != -1) {
return false;
} else {
// what here
}
};
but to overwrite the normal function what goes in "what here"?
Andrew Poulos
[toc] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-05-12 15:35 +1000 |
| Message-ID | <raKdnSsnnK2Ow-3OnZ2dnUVZ_sadnZ2d@westnet.com.au> |
| In reply to | #24136 |
On 12/05/2014 2:38 PM, Andrew Poulos wrote:
> I've been using a 3rd party web platform to build a web site.
>
> The platform can display its own alerts.
>
> I need to prevent one of the alerts but as I have no access to the code
> that is generating the alert so I'm wondering if there's a way to
> intercept it.
>
> If its the message in question then it is to be prevented from
> displaying otherwise the alert displays as "normal".
>
> I thought of doing
>
> window.alert = function(msg){
> if (msg.indexOf('Is empty') != -1) {
> return false;
> } else {
> // what here
> }
> };
>
> but to overwrite the normal function what goes in "what here"?
Ok, I'm now testing this
if (!window._alert) {
window._alert = window.alert;
}
window.alert = function(msg){
if (msg.indexOf('is empty') != -1) {
return false;
} else {
return window._alert.apply(this, arguments);
}
};
Is this the way to go?
Andrew Poulos
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-12 11:32 +0200 |
| Message-ID | <3910370.hJEAF5dPUy@PointedEars.de> |
| In reply to | #24137 |
Andrew Poulos wrote:
> if (!window._alert) {
> window._alert = window.alert;
> }
>
> window.alert = function(msg){
> if (msg.indexOf('is empty') != -1) {
> return false;
> } else {
> return window._alert.apply(this, arguments);
> }
> };
>
> Is this the way to go?
Not quite. You should not augment the host object referred to by “window”
with an “_alert” property (modifying its “alert” property is bad enough, but
I cannot see a better alternative here). Use a variable or a property of
your own object instead.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Simon Lewis <simonlewis2001@gmail.com> |
|---|---|
| Date | 2014-05-12 12:29 +0200 |
| Message-ID | <8761lb47e7.fsf@gmail.com> |
| In reply to | #24138 |
Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
> Andrew Poulos wrote:
>
>> if (!window._alert) {
>> window._alert = window.alert;
>> }
>>
>> window.alert = function(msg){
>> if (msg.indexOf('is empty') != -1) {
>> return false;
>> } else {
>> return window._alert.apply(this, arguments);
>> }
>> };
>>
>> Is this the way to go?
>
> Not quite. You should not augment the host object referred to by “window”
> with an “_alert” property (modifying its “alert” property is bad enough, but
> I cannot see a better alternative here). Use a variable or a property of
> your own object instead.
Nonsense.
It's perfectly fine to do that.
People tag things on to "window" in each and every JS project.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-12 13:30 +0200 |
| Message-ID | <2021642.a5K4omDOc0@PointedEars.de> |
| In reply to | #24139 |
Simon Lewis wrote:
> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
>> Andrew Poulos wrote:
>>> if (!window._alert) {
>>> window._alert = window.alert;
>>> }
>>>
>>> window.alert = function(msg){
>>> if (msg.indexOf('is empty') != -1) {
>>> return false;
>>> } else {
>>> return window._alert.apply(this, arguments);
>>> }
>>> };
>>>
>>> Is this the way to go?
>>
>> Not quite. You should not augment the host object referred to by
>> “window” with an “_alert” property (modifying its “alert” property is bad
>> enough, but
>> I cannot see a better alternative here). Use a variable or a property of
>> your own object instead.
>
> Nonsense.
>
> It's perfectly fine to do that.
>
> People tag things on to "window" in each and every JS project.
People like you who are lacking the minimum clue (on host objects).
We have discussed this here ad nauseam: When you assign to a property of a
host object, there is no telling what may happen because you cannot know the
actual runtime environment (you can limit the runtime environments that you
support, but that will only move the problem to the future, when there will
be a new runtime environment that you did not consider; see jQuery as an
example for that not-recommended approach).
You can be lucky and the host object does not have a property of that name
*and* allows augmentation. But there are other possibilities to consider:
A. The host object does not have such a property and does not allow
augmentation.
a. The assignment fails silently. The .apply() call will fail
because “undefined has no properties”.
b. The assignment throws a recoverable exception. Result like
with (a) unless caught before.
c. The assignment throws an unrecoverable exception (fatal error).
The program stops at the assignment with an error.
MSHTML is known for either (b) or (c) when the property name
is that of an ID or name in the document.
B. The host object already has such property with that name.
a. to c. like with (A), only that for (Aa) there is the additional
possibility that the .apply() call may either do something
unintended because the property value is kept (and another method
is called), or that it fails because the still-unchanged property
value is not callable (it could be a primitive value or refer to
an object that does not implement [[Call]]).
d. Modifying the property is successful but causes an unintended
action because of a built-in setter, or it breaks some
other functionality that the host object provides.
Whereas “has a property” means “has an own property with that name or
inherits one with that name through the prototype chain” here.
Subjecting a property of a host object (or a host object itself) to
conversion to Boolean, particularly supposed-to-be methods, or using a
property of a host object in a type-converting test, as above, can be error-
prone, too. (MSHTML is known for that.)
See the ECMAScript Language Specification, 5.1 Edition, section 8.6.2, for
details.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-05-12 14:54 +0200 |
| Message-ID | <XnsA32B97AB9DD2Ceejj99@194.109.133.133> |
| In reply to | #24139 |
Simon Lewis <simonlewis2001@gmail.com> wrote on 12 mei 2014 in comp.lang.javascript: > People tag things on to "window" in each and every JS project. You cannot know my JS projects, nor that of my neighbours, so such utterances make your js-credulity go below 1% here. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-05-12 15:36 +0200 |
| Message-ID | <XnsA32B9EB6EA338eejj99@194.109.133.133> |
| In reply to | #24141 |
ram@zedat.fu-berlin.de (Stefan Ram) wrote on 12 mei 2014 in comp.lang.javascript: > "Evertjan." <exxjxw.hannivoort@inter.nl.net> writes: >>Simon Lewis <simonlewis2001@gmail.com> wrote on 12 mei 2014 in >>comp.lang.javascript: >>>People tag things on to "window" in each and every JS project. >>You cannot know my JS projects, nor that of my neighbours, >>so such utterances make your js-credulity go below 1% here. > > When one just defines a global function (which happens > often) or variable, it becomes a property of the windows > object. Often is not "each and every". Many of my projects don't even have a "window". Serverside js, cscript-js, to name few. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Simon Lewis <simonlewis2001@gmail.com> |
|---|---|
| Date | 2014-05-12 15:40 +0200 |
| Message-ID | <87bnv32jz7.fsf@gmail.com> |
| In reply to | #24143 |
"Evertjan." <exxjxw.hannivoort@inter.nl.net> writes: > ram@zedat.fu-berlin.de (Stefan Ram) wrote on 12 mei 2014 in > comp.lang.javascript: > >> "Evertjan." <exxjxw.hannivoort@inter.nl.net> writes: >>>Simon Lewis <simonlewis2001@gmail.com> wrote on 12 mei 2014 in >>>comp.lang.javascript: >>>>People tag things on to "window" in each and every JS project. >>>You cannot know my JS projects, nor that of my neighbours, >>>so such utterances make your js-credulity go below 1% here. >> >> When one just defines a global function (which happens >> often) or variable, it becomes a property of the windows >> object. > > Often is not "each and every". > Many of my projects don't even have a "window". > Serverside js, cscript-js, to name few. each and every maybe not. This does not make your claim any the less ridiculous.
[toc] | [prev] | [next] | [standalone]
| From | Simon Lewis <simonlewis2001@gmail.com> |
|---|---|
| Date | 2014-05-12 15:43 +0200 |
| Message-ID | <877g5r2jtz.fsf@gmail.com> |
| In reply to | #24144 |
Simon Lewis <simonlewis2001@gmail.com> writes: > "Evertjan." <exxjxw.hannivoort@inter.nl.net> writes: > >> ram@zedat.fu-berlin.de (Stefan Ram) wrote on 12 mei 2014 in >> comp.lang.javascript: >> >>> "Evertjan." <exxjxw.hannivoort@inter.nl.net> writes: >>>>Simon Lewis <simonlewis2001@gmail.com> wrote on 12 mei 2014 in >>>>comp.lang.javascript: >>>>>People tag things on to "window" in each and every JS project. >>>>You cannot know my JS projects, nor that of my neighbours, >>>>so such utterances make your js-credulity go below 1% here. >>> >>> When one just defines a global function (which happens >>> often) or variable, it becomes a property of the windows >>> object. >> >> Often is not "each and every". >> Many of my projects don't even have a "window". >> Serverside js, cscript-js, to name few. > > each and every maybe not. This does not make your claim any the less > ridiculous. and btw, clearly this is not server side : your attempt at a side step is noted. You're wrong. Get over it.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-05-12 16:19 +0200 |
| Message-ID | <XnsA32BA60C4BC65eejj99@194.109.133.133> |
| In reply to | #24145 |
Simon Lewis <simonlewis2001@gmail.com> wrote on 12 mei 2014 in comp.lang.javascript: >>>> When one just defines a global function (which happens >>>> often) or variable, it becomes a property of the windows >>>> object. >>> >>> Often is not "each and every". >>> Many of my projects don't even have a "window". >>> Serverside js, cscript-js, to name few. >> >> each and every maybe not. This does not make your claim any the less >> ridiculous. > So wonderful, argumentation by screaming. My claim is that when one says "maybe it is not what I claimed", hiding that it is not maybe but obviously so, one diminishes his credibility. > and btw, clearly this is not server side : your attempt at a side step > is noted. You're wrong. Get over it. What "this" is not serverside-JS? not cscript-JS? not in-programme-JS? Remember you said: >>>>>People tag things on to "window" in each and every JS project. In my book "each and every Js-project" includes "each and every Js-project". Methinks my logical arguments are more convincing than your screaming. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-12 19:35 +0200 |
| Message-ID | <10627210.CkprS3AAyM@PointedEars.de> |
| In reply to | #24141 |
Stefan Ram wrote:
> "Evertjan." <exxjxw.hannivoort@inter.nl.net> writes:
>> Simon Lewis […] wrote […]:
>>> People tag things on to "window" in each and every JS project.
>> You cannot know my JS projects, nor that of my neighbours,
>> so such utterances make your js-credulity go below 1% here.
>
> When one just defines a global function (which happens
> often) or variable, it becomes a property of the windows
> object.
You meant _window_, and no. It becomes a property of the ECMAScript global
object with the attribute [[DontDelete]] (ES3) or lacking the [[Writable]]
attribute (ES5.1+); see ES 5.1, §§10.2.3 and 10.4.1 [0]. Anything more
depends on the runtime environment and is not reliable (cross-frame
referencing excluded).
The ECMAScript global object can be referred to in the global execution
context with “this” because it is its /this/ value. Since there is no other
standards-compliant way, particularly not a built-in property, to refer to
the global object (yet) (returning the “this” value from an instantly called
anonymous function does not work in strict mode), it is recommended to
define a variable or property that can be used instead. For example:
var _global = this;
JSX provides “jsx.global” since several revisions in order to avoid another
global variable. [1] (The main compatibility layer, JSX:compat.js, can
still provide the old “_global” if needed. [2]) Of course, in properly
structured code it is only seldom necessary to refer to the global object
from local context in the first place.
____________
[0] <http://ecma-international.org/ecma-262/5.1/#sec-10.2.3>
<http://ecma-international.org/ecma-262/5.1/#sec-10.4.1>
[1] <http://PointedEars.de/wsvn/JSX/trunk/object.js>
[2] <http://PointedEars.de/wsvn/JSX/trunk/compat.js>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | garrett.smith@acxiom.com |
|---|---|
| Date | 2014-05-14 09:57 -0700 |
| Message-ID | <106f0eba-078e-471e-a71c-66837dcfba0e@googlegroups.com> |
| In reply to | #24137 |
On Sunday, May 11, 2014 10:35:41 PM UTC-7, Andrew Poulos wrote:
> On 12/05/2014 2:38 PM, Andrew Poulos wrote:
>
> > I've been using a 3rd party web platform to build a web site.
>
> >
>
> > The platform can display its own alerts.
>
> >
>
> > I need to prevent one of the alerts but as I have no access to the code
>
> > that is generating the alert so I'm wondering if there's a way to
>
> > intercept it.
>
> >
>
> > If its the message in question then it is to be prevented from
>
> > displaying otherwise the alert displays as "normal".
>
> >
>
> > I thought of doing
>
> >
>
> > window.alert = function(msg){
>
> > if (msg.indexOf('Is empty') != -1) {
>
> > return false;
>
> > } else {
>
> > // what here
>
> > }
>
> > };
>
> >
>
> > but to overwrite the normal function what goes in "what here"?
>
>
>
> Ok, I'm now testing this
>
>
>
> if (!window._alert) {
>
> window._alert = window.alert;
>
> }
>
>
>
> window.alert = function(msg){
>
> if (msg.indexOf('is empty') != -1) {
>
> return false;
>
> } else {
>
> return window._alert.apply(this, arguments);
>
> }
>
> };
>
>
>
> Is this the way to go?
>
Intercepting with what is known as "before advice".
That's not a bad strategy, but the implementation y0ou've chosen will cause errors.
window._alert is a host object; not necessarily a function. It is implemented in some implementations, notably most versions of Internet Explorer, as what ES6 calls an "exotic" host object.
In these implementations, there is no `apply` method on the alert property. Attempts to even access properties of `alert`, much less call them, have been shown to result in errors.
The solution is to either (a) avoid the second branch of trying window._alert.apply, or (b) don't intercept alert in the first place (unless your motives are ethically subversive; to cause problems with code maintenance within your or organization).
Here:
https://twitter.com/xkit/status/17276847991
Regards,
--
Garrett
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2014-05-13 18:00 +0100 |
| Message-ID | <8R65vYRo+kcTFwRW@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #24136 |
In comp.lang.javascript message <862dneogqrcsze3OnZ2dnUVZ_gCdnZ2d@westne
t.com.au>, Mon, 12 May 2014 14:38:33, Andrew Poulos
<ap_prog@hotmail.com> posted:
>I've been using a 3rd party web platform to build a web site.
>
>The platform can display its own alerts.
>
>I need to prevent one of the alerts but as I have no access to the code
>that is generating the alert so I'm wondering if there's a way to
>intercept it.
>
>If its the message in question then it is to be prevented from
>displaying otherwise the alert displays as "normal".
>
>I thought of doing
>
>window.alert = function(msg){
> if (msg.indexOf('Is empty') != -1) {
> return false;
> } else {
> // what here
> }
>};
>
>but to overwrite the normal function what goes in "what here"?
Consider the implications of
Fred = window.alert
function Bert(X) { Fred("*** " + X + " ***") }
window.alert = Bert
alert(333)
which alerts "*** 333 ***".
The code will probably cause an Eruption of the Lahn; but that is
nowadays a customary side-effect.
--
(c) John Stockton, nr London, UK. For Mail, see Home Page. Turnpike, WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
DOS/Win/UNIX now 2.0.6; see my <http://www.merlyn.demon.co.uk/pc-links.htm>.
[toc] | [prev] | [next] | [standalone]
| From | garrett.smith@acxiom.com |
|---|---|
| Date | 2014-05-14 09:57 -0700 |
| Message-ID | <e8ca1de4-e47f-4fba-bfc6-20dc1a3ed36d@googlegroups.com> |
| In reply to | #24136 |
On Sunday, May 11, 2014 9:38:33 PM UTC-7, Andrew Poulos wrote:
> I've been using a 3rd party web platform to build a web site.
>
>
>
> The platform can display its own alerts.
>
>
>
> I need to prevent one of the alerts but as I have no access to the code
>
> that is generating the alert so I'm wondering if there's a way to
>
> intercept it.
>
>
>
> If its the message in question then it is to be prevented from
>
> displaying otherwise the alert displays as "normal".
>
>
>
> I thought of doing
>
>
>
> window.alert = function(msg){
>
> if (msg.indexOf('Is empty') != -1) {
>
> return false;
>
> } else {
>
> // what here
>
> }
>
> };
>
>
>
> but to overwrite the normal function what goes in "what here"?
>
>
>
> Andrew Poulos
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web