1

Is there a way to find out the id of the IE window that generates alert boxes? I assume it is the document or window itself.

Either simple html or jQuery can be used.

I tried something like:

var id = $(this).parent().attr('id');

but to no avail.

Ultimately I want to find out the ID of the window/document which generates javascript alerts so I can override it.

Thanks.

BeraCim
  • 2,317
  • 8
  • 49
  • 78
  • You mean the document title? Or `window.name`? Or `document.body.id`? Not sure what "ID of the window" means. – Crescent Fresh Dec 10 '09 at 03:36
  • I wanted to override javascript alerts, and I assume that it comes from the actual browser itself. But I'm not sure whether that means it starts from window or document, so I just threw the question in the air for clarification. HTH. – BeraCim Dec 10 '09 at 03:47
  • See my answer, there's a link that tells you how to do it! – Mike Gleason jr Couturier Dec 10 '09 at 03:48
  • @ Mike Gleason jr Couturier: thanks. I'm currently looking at how to just override the specific alert, since I want to confirm that a particular alert box has been overriden as part of my unit test. – BeraCim Dec 10 '09 at 03:55
  • Cool! Just look at the link then! – Mike Gleason jr Couturier Dec 10 '09 at 05:02
  • yeah I want to do something like if (windows.alert().text == 'specific text') override this alert. Haven't been able to figure it out yet. – BeraCim Dec 10 '09 at 05:26

2 Answers2

2

If the document did not specified an ID attribute for the body, there's not much info you can gather... the html tag doesn't specify an ID attribute either...

You must build a mechanism yourself to identify your windows..

See the jQuery data() to attach a custom "property" to a DOM object if you want to keep your windows handles somewhere.

To override the alert function, see my response to this question: JavaScript: Overriding alert()

Good luck

Community
  • 1
  • 1
0

Not sure why you would need to do this but if you mean that you want to override the alert function it's pretty easy:

alert = function() {
    // do some custom stuff here
};
Jared
  • 8,390
  • 5
  • 38
  • 43