javascript-events

How to attach an event to onSubmit event of form with chaining earlier attached methods as well?

旧街凉风 提交于 2019-12-22 08:10:09
问题 Actaully my application is having hundreds of pages. Now i have to attach an event 'disablePage' on onSubmit of form. I don't want to go to each and every page and write: <form name="frmname" onSubmit="disablePage();"> What i am doing right now is:- excerpt from common.js file; [ included in all pages ] /* we have to attach 'attachFormSubmit' method on onLoad event, otherwise forms[0] will always be null. If there is any alternative, then please suggest one */ if (window.addEventListener){

How to load a part of page every 30 seconds [duplicate]

∥☆過路亽.° 提交于 2019-12-22 08:05:06
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: jQuery Ajax request every 30 seconds I know we can load a part of page on some event. I also know we can load whole web page every specified time. But i wanted to know how to load a part of page every 30 seconds. 回答1: function refreshPage() { $.ajax({ url: 'ajax/test.html', dataType: 'html', success: function(data) { $('.result').html(data); }, complete: function() { window.setTimeout(refreshPage, 30000); } });

prevent window.onhashchange from executing when hash is set via JavaScript

十年热恋 提交于 2019-12-22 07:05:24
问题 I use the window.onhashchange function to execute code when the User changes the hash of the page: window.onhashchange = function() { /* do something */ }; In some functions I also set the hash via JavaScript: window.location.hash = "#abc"; I want to prevent the onhashchange event from firing when I set the hash via JavaScript. What I have tried so far: var currently_setting_hash = false; window.onhashchange = function() { if (currently_setting_hash) return; //... } currently_setting_hash =

how to catch a state change event ONCE with history.js?

我只是一个虾纸丫 提交于 2019-12-22 06:58:48
问题 I have an example code below where if you click the links, then use back and forward, each state change will cause more and more hits on the 'statechange' event. Instead of the one that I expect. Links: https://github.com/browserstate/history.js http://docs.jquery.com/Downloading_jQuery Code: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>History start</title> </head> <body> <h1>Headline</h1> <hr> <div id="menu"> <ul> <li> <a href=

Watch for a property creation event?

送分小仙女□ 提交于 2019-12-22 06:37:18
问题 I need to be able to determine when an object is created (not a DOM element -- a javascript object). An answer to this question has some very useful looking code for creating observable properties, so you can have a function fire when a property changes. In my situation I need to do something when the object/property is created, not an existing property changed, and my limited understanding of such matters did not help me figure out if or how I could use that code to do this after much

jQuery - Calling a function inline

纵然是瞬间 提交于 2019-12-22 06:00:24
问题 I am trying to pass one variable to a jQuery function inline (ie: using an onMouseOver="function();" within the actual link (which is an area tag from an image map)). The function is only being called if I place it before the $(document).ready(function(){ line, but doing this is causing all sorts of problems with jQuery. All I want is for a simple tag (such as <area shape="circle" coords="357,138,17" onMouseOver="change('5');" id="5" /> to launch a function that is contained within the normal

Jquery trigger custom event in iframe window

天涯浪子 提交于 2019-12-22 05:49:09
问题 I'm having trouble triggering a custom event in an iframe from the parent document. In the child I have code like this: $(window).on( 'my-event', function() { console.log( "GOT IT" ) } ) In the parent I get the iframe and try to send an event: iframe = document.getElementById( 'content-frame' ) $(iframe.contentWindow).trigger( 'my-event' ) The event doesn't arrive. I've tried using 'document' instead of window, but still without luck. Can this be done with jquery? I'm hoping there is a simple

remove a previous stroke (make a temporary line) - Javascript / HTML5

送分小仙女□ 提交于 2019-12-22 05:42:23
问题 I am trying to make a simple paint application and I want the lines to sort of preview the line after you specify a lines start point. The corresponding javascript is like this: var Edges = new Array(); var Vertecies = new Array(); var Mouse = {x:0, y:0} function findPos(obj) { var curleft = 0, curtop = 0; if (obj.offsetParent) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; } while (obj = obj.offsetParent); return { x: curleft, y: curtop }; } return undefined; } function addEdge()

Swipe action binding in knockoutjs

99封情书 提交于 2019-12-22 05:41:12
问题 I am using knockout as main framework in my application and it has to support tablets and mobile devices. As the framework is built on binding handlers I wonder how can custom binding to actions (like swipe and other device specific ones) be achieved, or maybe there is something like this done? 回答1: Probably too late, but here is a library that adds touch binding to knockoutjs: https://github.com/yaroslavya/knockouch 回答2: Create a bindingHandler . Here you go an example of a real project ko

Swipe action binding in knockoutjs

纵然是瞬间 提交于 2019-12-22 05:41:03
问题 I am using knockout as main framework in my application and it has to support tablets and mobile devices. As the framework is built on binding handlers I wonder how can custom binding to actions (like swipe and other device specific ones) be achieved, or maybe there is something like this done? 回答1: Probably too late, but here is a library that adds touch binding to knockoutjs: https://github.com/yaroslavya/knockouch 回答2: Create a bindingHandler . Here you go an example of a real project ko