Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
The reason behind of posting this question is to understand the basic differences and use cases of the Event and EvenHandler.
Event:- In computing, an event is an action or occurrence detected by the program that may be handled by the program. Typically events are handled synchronously with the program flow, that is, the program has one or more dedicated places where events are handled.
EventHandler:-
A function or method containing program statements that are executed in response to an event. An event handler typically is a software routine that processes actions such as keystrokes and mouse movements. With Web sites, event handlers make Web content dynamic. JavaScript is a common method of scripting event handlers for Web content.
Very basic example is you click on login button on facebook, there is corresponding event handler for click on login button which tells facebook app that user trying to login
You cannot compare the both Handler and event.
All Handlers are stored with a HandlerManager which also manages dispatching any type of event (including new ones you create yourself).
More over
Handlers are passed an Event object with all the Event details as their only parameter i.e Event
They may mean different things, depending on a specific context. A general meaning of an event is a an action or occurrence somewhere in the program; normally events are handled by the program in modules called handlers.
For example in Java you may an event triggered by the push of a button; what the program does when that button is call the code in the handler for that particular event.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I am currently building a JavaScript tool that takes in an address and runs it through a series of functions that outputs a Boolean value of whether the address is within a range of addresses. From this output the tool will dynamically add cards to the page based on the output. My problem at the moment is that if the event listener is clicked more than once it just continues to add the cards to the page. Is there an event listener that will take in a click event but only fire the first time the event is triggered? If not am I better off just writing a function to remove the click event once it has been fired? I am more than happy to include the code from the project but seemed unnecessary.
addEventListener has an option to listen for an event only once:
const button = document.querySelector("button");
button.addEventListener("click", onClick, {
once: true
});
function onClick() {
window.alert("Clicked!");
}
<button>Try clicking me twice</button>
This option is supported in all major browsers except for Internet Explorer (which has been discontinued)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
When you click "save" on a form , 2 jquery events I know get triggered. Actually I was using both but just today I realised one is enough :) . But still let's say you define both, which one would be triggered first. $("#btnSaveForm").click() or $("#btnSaveForm").submit()
What I also noticed as soon as a click handler is triggered, the GUI basically freezes as long as this click handler is completely executed(Even if there is a ajax call done inside the handler). But still the GUI remembers what you did and executes the clicks afterwards.
The order of which things are executed is as follows :
User clicks the submit button
The onclick function is executed
The browser submits the page to the url specified in the action of
the form
As you can see in this example, the button triggers first and the form triggers right after.
Maybe you are using sync ajax handler if you are experiencing Frozen GUI after submitting your form.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am working on a small project where I have to submit a form to a website.
The website is, however, using onclick event to submit the form (using javascript).
How can the onclick event be simulated in python?
Which modules can be used? I have heard about selenium and mechanize modules. But, which module can be used or in case of both, which one is better?
I am new to web scraping and automation.So,it would be very helpful.
Thanks in advance.
Ideally you don't even need to clicks buttons in these kind of cases.
All you need is to see at what webservice does the form sends request when clicked on submit button.
For that open your developer's control in the browser, Go to the Network tab and select 'preserve log'. Now submit the form manually and look for the first xhr GET/POST request sent. It would be POST request 90% of times.
Now when you select that request in the request parameters it would show the values that you entered while submitting the form. Bingo!!
Now all you need to do is mimic this request with relevant request headers and parameters in your python code using requests. And Wooshh!!
Hope it helps..
There is no silver bullet in simulating onclick events on a web page. It is pretty much use-case specific, but here are some points and guidelines.
In general, there are two approaches:
use browser developer tools, open the network tab, make the click and see what request is being sent to the server. Then, simulate this request in Python, with, for example, requests.
use selenium which would fire up a real browser where you would find the specific element and click via .click() method
mechanize would not execute/trigger the onclick function, because executing onclick requires executing javascript which mechanize cannot do.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Suppose an application has a chat module containing messages. There is a jQuery click handler on said chat module that fires a series of focus related events whenever it detects a click.
Now suppose that when certain messages within the chat module are clicked, the event never bubbles up and a click event is never activated on the chat module.
How would I troubleshoot such an issue? I have a theory that somewhere in the application an intermediate element between the message click handler and the chat module click handler which is capturing the event and calling e.stopPropagation on it. There is currently no tools in Chrome to trace event propagation though.
What is the best way to trace event propagation in Chrome?
Override jQuery.Event.prototype.stopPropagation with a function containing a debugger statement:
jQuery.Event.prototype.stopPropagation = function() {
debugger;
};
From there perform the user actions that will fire the stopPropagation event; this time however a the debugger statement will cause the JavaScript to pause execution and you can observe the stack trace to see where it is being called from.
Put an ever-loving crap-ton of console logs everywhere. Not the most elegant solution, but it allows me to see what information is getting passed and where any and all hiccups are.
console.log(var);
I may suggest you to open the Chrome console (F12) go to elements, select the element of your interest and with right mouse click set the subtree modification.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm rather new to Javascript and some of the syntax is not very clear to me. I've usually copied example code from the internet when I needed it, but I would like to understand it better.
Can someone explain, in simple terms, how javascript knows to call the function supplied, and how it knows to do it asynchronously? Is there something that tells it do do this, or is it just built into the language?
Thanks
Whenever you want to something when something happens (and that something is outside the control of JavaScript (e.g. "When the user clicks on a button" or "When the HTTP response is received from the network".)) you typically use an Event Listener.
This is a function that you tell JavaScript to run when the event happens.
They are typically set up by using the addEventListener method or by assigning a function to a property with a predefined name on the right kind of object.
When the event happens some code (typically (in a browser this is almost always) provided by the underlying environment) will check to see if any appropriate event listener functions exist and executes them.