javascript-events

Event to be triggered when leaving website or closes the browser

瘦欲@ 提交于 2019-12-13 03:18:26
问题 I´m trying for a while execute a javascript function when a user leaves web site by typing a address in the browser and hits return or the user closes the brower clicking in the 'x' button. I tried the unload event but I cannot get the alert this is what I am doing: $(window).unload(function () { alert("Are you sure?"); }); also $(body).unload(function () { alert("Are you sure?"); }); I am running out of idea! 回答1: You can listen to beforeunload event that fires before the unload event, when

How to trigger an event after clicking two different button in Javascript

风流意气都作罢 提交于 2019-12-13 02:49:50
问题 I was wondering how I can trigger an event after two different buttons being clicked. Specifically I have some buttons with different ids and I want when I click two specific buttons from them to trigger an event. I thought that this can be happen If I call some function in the first on click event and inside this function I can call another function if the second button being clicked. It does not seem to work, so I need your help. Thanks. (if anyone needs more code please comment to upload

`mousemove` and triggering a custom event

删除回忆录丶 提交于 2019-12-13 02:49:45
问题 In a mousemove event: $(document).on('mousemove', function( e ){ console.log( e.pageX ); console.log( e.pageY ); }); as you can see, we can use pageX and pageY to get the x and y co-ordinates of mouse position. But, what I want is to trigger a custom event of mine on mousemove and would like to get these pageX and pageY values in that custom event of mine. To be more clear, what I would like to do is: $(document).on('mousemove', function(){ $(document).trigger('myevent'); }); $(document).on(

IE Issue with jquery and JS

落爺英雄遲暮 提交于 2019-12-13 02:37:21
问题 Im trying to write a function that transfer the items from the basket and push it in the cart. the problem I am facing at the moment is that although this code works fine in FF and Chrome it isnt recognising the products. Many Thanks in Advance. var modals_pool = {}; $('.deal_order_btn').live('click', function (e) { e.preventDefault(); deal = {}; deal.id = $(this).attr('deal_id'); deal.title = $(this).attr('deal_title'); deal.items = []; additional_total = 0; $(this).parents('.deal_item

First parameter to event handler

a 夏天 提交于 2019-12-13 02:18:30
问题 If I have some event handlers registered inline with my markup (deprecated, I know) like span id="..." onclick="foo(p1,p2,p3)" how can I access the "event" object in the event handler function foo? Changing the above to span id="..." onclick="foo(event,p1,p2,p3)" and then using it in "foo" like function foo(e,p1,p2,p3) { if (!e) e = window.event; } seems to work but I don't see it documented anywhere so I am wary of using it. In other words, is the first parameter to a inline event handler

What is the best way to make the Yahoo media player autostart, jQuery?

心不动则不痛 提交于 2019-12-13 01:00:33
问题 Yahoo has a mediaplayer to play media on a webpage: http://mediaplayer.yahoo.com/ but there is no option to make it auto start. What is the best way to make it autostart, by hacking into the code, or it can also be using jQuery to "click" on one of the media to auto start it, although, how do you know the Yahoo code has finish initializing? We can use a setTimeout(function() { // click first one }, 3000) but it seems too much of a hack. 回答1: There is an option for this. Plz check at this page

window.onbeforeunload not firing in child window

我的未来我决定 提交于 2019-12-13 00:26:16
问题 I want to bind a function to the beforeunload event of a child window in Javascript. I have the following code: newWind = window.open(settings.url, "Dialog", "width=" + settings.width + ",height=" + settings.height + ",resizable=" + settings.resizable + ",scrollbars=" + true); newWind.onunload = function() { alert('test'); } Works fine in Firefox, but fails in IE7. Can anyone see what I am doing wrong? 回答1: newWind.onunload = function() { alert('test'); } IE won't let you assign a function

Do browser key events fire (bubble) only to elements in focus?

别来无恙 提交于 2019-12-12 23:25:32
问题 Experimental evidence has led me to believe that key (up, down, press) events fire (in bubble phase) only to elements in focus . This behavior may be intuitive, obvious and/or desirable, but haven't seen this documented anywhere, so I was hoping the community would confirm my "theory". Otherwise, I have some code that's not properly letting these events bubble up. Thanks! 回答1: key events are always targeted to the element that has focus, and bubble up until cancelled. You cannot press a key

proper use of onmousemove

百般思念 提交于 2019-12-12 22:41:22
问题 I am trying to write some javascript that draws a line by dragging the mouse, and then removes it when you let go of left click. <!DOCTYPE html> <html> <head> <script type="text/javascript"> window.onload = function() { window.stop = false window.canvas = document.getElementById("e"); window.context = canvas.getContext("2d"); canvas.width = document.documentElement.clientWidth; canvas.height = document.documentElement.clientHeight; window.pos = Shift(); } function Shift() { e = window.event

JavaScript pass mouseenter event to element that is underneath another element

 ̄綄美尐妖づ 提交于 2019-12-12 22:06:43
问题 I'm trying to build a little calendar app sort of like Google Calendar. I'm trying to create events with a click and drag functionality so that the events align to a grid. I'm trying to tie the dragging to TD elements below the event DIV element, which works when moving downwards (lengthening the event), but it doesn't work moving upwards (shrinking the event). What occurs is that the mouseenter event is fired for the event DIV element, but it is never fired for the underlying TD. If you try