Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to get the origin of an alert box?

I work with some very large and confusing JavaScript files that I did not write. Sometimes an alert will come up but I don't know where it's coming from.

You could search all files for the text contained in the alert but if that text is dynamic it won't work.

Is there a way to set a breakpoint in order to intercept an alert?

like image 464
user1873073 Avatar asked Jan 04 '13 14:01

user1873073


People also ask

How do I get the alert box in the middle?

Center the Alert Message Box Using CSS Under that, style it accordingly and position it to the center. Use the “top” and “left” CSS properties to achieve this. Set them as 50%, but as you can see the button below, so the property to 40% for correct alignment.

How do you inspect an alert box?

1st Step: Launch the website "https://demoqa.com/alerts". 2nd Step: Click on the "click me" button, as highlighted in the following screenshot, to see the confirmation alert box. 3rd Step: Once the confirmation box is open, the user can either accept or dismiss the alert box using Alert. accept(); or Alert.

Can we design alert box?

The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.

Which JavaScript method is used to write into an alert box?

One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen.


2 Answers

At the very top of your HTML:

window.alert = function() {     debugger; } 

debugger is a statement that invokes any debugging functionality available. With developer tools open, you'll automatically hit a breakpoint whenever alert is called. You can then inspect the call stack to see exactly what called the custom alert function.

like image 122
josh3736 Avatar answered Sep 19 '22 17:09

josh3736


It may or may not be helpful to you, but you can overwrite the alert function to do whatever you want with it. For example, instead of alert boxes, you could have it log the message to the console.

window.alert = function(msg) {     console.log(msg); } alert('test'); 
like image 43
Brian Glaz Avatar answered Sep 18 '22 17:09

Brian Glaz