If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

"But alerts are considered to be obsolete. In practice you should use DOM methods to display a message to your user."

Any sensible person would interpret that as referring to document.getElementById() and innerHTML.

I have never heard anyone claim that alert() was a DOM method. But you may be right - on a geeky and pedantic level. Why are you seeking to start a pointless argument? How can your intervention be of the slightest use to the OP?

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

It is apparant that alert() and prompt() are defined in the browser simply from viewing the different way (appearance) in which they are rendered in different browsers.

What practical difference that makes eludes me. But my point was that alerts are obsolete and should not be used. That is true however they originate, DOM method or not.

Edit: alert() may well be defined in the browser but like Airblader I do not think that makes it part of the HTML DOM. So I think that the statement that alert() is a method of the DOM is not correct. I agree with Airblader - It may be part of every DOM's implementation, but it is not part of the DOM.

Last edited by Philip M; 10-10-2013 at 11:28 AM.

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

I have searched my way through the different DOM level specifications and I can't find any mention of a specified(!) method named like that. Unfortunately, it also doesn't seem to be specified anywhere else and to me it looks like it's a method that every implementation seems to have, but which is not part of the underlying specification that is implemented. Not entirely surprising, knowing how mixed up all the different implementations are, and yet interesting to see that every browser supports it.

In other words: It may be part of every DOM's implementation, but it is not part of the DOM.
Just because every implementation of an interface implements another method, doesn't make this method be part of the interface.

However, I might just be missing something. So if anyone can point me to where it is actually defined, if it is, I'd be glad to see it. But I'd be surprised to find it to be a part of the DOM as it has nothing to do with the DOM, really. I'd expect it to be part of the Javascript specification, or maybe a completely different specification. But I'm happy to be proven wrong.

And I'm sorry for reviving this discussion. I actually find it very interesting to see where such a commonly used (even if not recommended) method is defined. But in terms of truth I also think it's important to give a prove of why it allegedly is part of the DOM – at least I couldn't verify that right away (but neither could I disprove it reliably, I just tend to assume it's wrong unless I find prove that it is true).

I have searched my way through the different DOM level specifications and I can't find any mention of a specified(!) method named like that. Unfortunately, it also doesn't seem to be specified anywhere else and to me it looks like it's a method that every implementation seems to have,
...

However, I might just be missing something. So if anyone can point me to where it is actually defined, if it is, I'd be glad to see it. But I'd be surprised to find it to be a part of the DOM as it has nothing to do with the DOM, really. I'd expect it to be part of the Javascript specification, or maybe a completely different specification. But I'm happy to be proven wrong.

did you really look? HTML5 is not very obscure imho... i'll chalk it up to a "senior moment" because i know you do good work around here...

a rose by any other name would still smell so sweet. who cares where it came from, it's just there. as my mom used to say when she didn't understand something: "that's just how god made it". also, alert's not in node.js, webworkers, ASP classic, and many other JS implementations that follow (or try to follow) the ECMAScript spec.

to me, this is not surprising, the spec doesn't even spec "window", much less its methods...

Last edited by rnd me; 10-10-2013 at 05:24 PM.

Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

I mostly focused on the DOM spec, since that is what this was about. I read that it is part of the HTML5 spec, but that can't be where it originates from, since it existed before HTML5.

a rose by any other name would still smell so sweet. who cares where it came from, it's just there. as my mom used to say when she didn't understand something: "that's just how god made it"

I guess after a year of working for an international company as a customer with countless specs and documents to write and update every day, I sort of got used to thinking "in specs". And seeing how much implementations differ in this area, it feels worth knowing to me where particular things are even specified. And there are quite a few cases where the spec matters – for example when it comes to decide whether something is a bug or intended behavior.

In any case, at least being part of HTML5 strongly suggests that alert is indeed not a DOM method.

In any case, at least being part of HTML5 strongly suggests that alert is indeed not a DOM method.

it was around, un-spec'd, before HTML5 formalized it. it most certainly is a dom method, the link i posted contains the fragment "dom-alert", and that's in an address pointing to a W3 spec. it doesn't get much more official than that. mozilla refers to the HTML5 spec in its mdn page on alert().

Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

If it's not in the DOM spec, it is not a DOM method. And your link is the HTML5 spec, which is not DOM. The MDN talks about Gecko DOM, which is an implementation. If Mozilla sees it as part of their DOM, that's fine. That makes it part of their DOM's implementation, not part of the DOM. If I write my own spec and call something "dom-foobar", it still isn't part of the DOM either.

So again: Unless the DOM spec itself says that alert is part of the DOM, it simply isn't, not per spec.

If it's not in the DOM spec, it is not a DOM method. And your link is the HTML5 spec, which is not DOM. The MDN talks about Gecko DOM, which is an implementation. If Mozilla sees it as part of their DOM, that's fine. That makes it part of their DOM's implementation, not part of the DOM.

If I write my own spec and call something "dom-foobar", it still isn't part of the DOM either.

mozilla sees it as a part of the HTML5 implementation. the first link was an archived page not hosted on the mdn page shown to establish the undocumented nature of alert() prior to HTML5, the current copy of the page, linked secondly, refers to an html5 specification.

i thought the debate was that alert() is not spec'd, which it clearly is. then it somehow got tied into the dom...

i think the confusion here lies in a somewhat ambiguous usage of the term DOM. In one respect, we often mean the proper HTML DOM when we say DOM, stuff like getElementsByTagName, children[], nodeValue, etc.

But, anything that in-browser JS reaches is considered part of the browser's DOM, including the "window" object spec'd as document.defaultView. This is why for example, xmlHttpRequest is spec'd using "DOMString"s instead of "String"s. If a browser wants to support HTML5, it MUST support alert().

i agree that alert() is not part of the html document model, but that's not to say it's not part of the JS DOM, which encompasses more than just the document, stuff like ajax, addEventListener, registerPrototcolHandler and all that fun stuff.

yes, it's confusing, but it also doesn't really matter one bit.

Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

i thought the debate was that alert() is not spec'd, which it clearly is. then it somehow got tied into the dom...

It was about whether it is a DOM method eversince the discussion started, I just pointed out that I failed to find it's specification in the DOM spec, which indicates that it is not part of the DOM.

Yes, terms may be a little foggy here and I guess one could argue that it is part of "one" DOM, but not part of "another" DOM. Which would still lead me to say that "it is definitely part of the DOM" is simply wrong. It is part of some DOM "extensions", but there is only one Document Object Model specification, and that specification does not mention alert.

but it also doesn't really matter one bit.

Surely not to many developers who only use it. It probably matters more to those implementing the specs. Specs are a pain in the a** most of the time, but every now and then they are very useful. I experience it almost every day at work… For example, we have been developing a new feature for several weeks, establishing some new functionality in an existing interface by extending it with some new values. Suddenly the other party tells us that they meant to send us strings, not numbers. We are talking tens of thousands of dollars here for additional development to fix this, and luckily we had specs that clearly stated that we had agreed on numbers.