javascript

How to intercept the onclick event

I'd like to intercept the onclick event of a button (not submit) before the page posts back from the onclick. I'm having some trouble: $(document).ready() { function() { function validate() { ... } var oldOnClick = $("input[value=OK]").attr("onclick"); $("input[value=OK]").attr("onclick", "if(!validate()) { re...

How to filter out asynchronous requests in ProgressListener?

I am using progresslistener to monitor user actions on web pages, when user click a link, I am trying to check if this request will redirect user to the new location or it is an Ajax WebHttpRequest only (It won't reload or redirect the page). here is the code I am using: ProgressListener.prototype = { QueryInterface: function(aIID) {...

Good resources for Javascript 2d game programming?

I'm sure this question's come up before, but I can't find any reference to it. As an exercise, I've decided to look into Javascript for game programming. While it's far from being the best language for that, I do like the idea that it's cross platform and it's always available as a web page. So I thought I'd see what I could do with it....

Is it possible for a browser plug-in/toolbar to identify the current URL of an iFrame?

My site frames content like DiggBar and the Facebook share bar. If a user wants to break out of the framed content, and visit the underlying site directly, we cannot guarantee the current page will be displayed, since there is no way for JS or HTML to query the current URL of an iFrame (for security reasons). All we can do is show the ...

Explaining some of John Resig's ninja code

Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object = args.shift(); return function(){ return fn.apply(object, args.concat(Array.prototype.slice.call(arguments))); }; }; var myObject = {}; function myFunction(){ return this...

Global onBlur/onFocus

We have, like everyone else, forms all over our web app. So far we've been using the following (or some variation) in most every form element: class="formThingy" onFocus="document.theForm.theField.className='formThingySelected';" onBlur="document.theForm.theField.className='formThingy';" It's a pain. Is there an easy way to do g...

jQuery treat strings as variables?

I've done some work with Scriptaculous, and now I'm dipping my feet in to JQuery to see which of the two frameworks I like working with the most. I am running in to some behavior that strikes me as odd... $.ajax({ type: "POST", url: "addcart.php", data: "userID="+ userID + "&cardID=" + cardID + "&cardQTY=" + cardQTY + "&set=m...

jQuery Ajax loading content from another page of the site

I'm trying to pull the contents of Div from another page of the site I'm working on and update the Div on the current page. I want to do this so I don't need a page reload. The Ajax call I'm making works fine in Firefox, it updates the Div with the content from the other page of the site. The problem is it breaks in IE, when I try to get...

Javscript inheritance implementation question

In his sitepoint article about javascript inheritance, Harry Fuecks explains a way of implementing inheritance as follows: function copyPrototype(descendant, parent) { var sConstructor = parent.toString(); var aMatch = sConstructor.match( /\s*function (.*)\(/ ); if ( aMatch != null ) { descendant.prototype[aMatch[1]] = p...

Slow Response in checkbox using JQuery

Hi to all. I'm trying to optimize a website. The flow is i tried to query a certain table and all of its data entry in a page(w/ toolbars), work fine. When i tried to edit the page the problem is when i click the checkbox button i have to wait 2-5sec just by clicking it. I limit the viewing of entry to 5 only but the response on checkbox...

Suppress anchor tag <a> href when using jquery

I have the following code: <script type="text/javascript"> $(document).ready(function() { $("#thang").load("http://www.yahoo.com"); $(".SmoothLink").click( function() { $("#thang").fadeOut(); $("#thang").load($(this).attr("href")); $("#thang").fadeIn(); }); }); </script> <...

UTC within Site

Hi, I am working on a website that will only be available via the intranet but is a website that is Australia wide ONLY. The thing is, I have been asked to look into making the site UTC and was wondering how I could go about displaying a clock or determing which timezone the site in running in and so perhaps display a clock on the home...

Javascript performance ? - Put events in html tag, or bind them?

I'm wondering which is better for performance... I have a "web app" sort of thing. It has a lot of javascript. When a button is clicked, a hidden div becomes visible. This new div has 5 buttons. Which is better for performance: 1.) put the button click events in the html tag of each button like onClick="alert('hey');" 2.) Attach events ...

Javascript Date.UTC() function is off by a month?

I was playing around with Javascript creating a simple countdown clock when I came across this strange behavior: var a = new Date(), now = a.getTime(), then = Date.UTC(2009,10,31), diff = then -now , daysleft = parseInt(diff/(24*60*60*1000)); console.log(daysleft ); The daysleft is off by 30 days. What is wrong with this code? Edit...

Div onblur event called when clicking checkbox inside div

I have a popup div and want to hide it when users click outside of the div. Inside the div, I have a checkbox... Problem is, the div's onblur event gets fired when trying to click on the checkbox. I put cancelEventBubble code on the onclick of the checkbox but the onblur fires before the checkbox onclick event... any ideas or suggestio...

External JSON data with offline development

I am developing a web app that accesses some external JSON data. I'm currently using jQuery's getJSON to get the data and call the callback. My internet at home is terrible, so I'm regularly not connected. I am looking for a way to develop this app while disconnected from the internet. My initial thought was to have an OFFLINE variabl...

Does a real ECMAScript implementation exist, or is it just a spec?

I read both of the links below http://en.wikipedia.org/wiki/ECMAScript http://stackoverflow.com/questions/912479/what-is-the-difference-between-javascript-and-ecmascript My question is, does ECMAScript exist as something I can download and use instead of JavaScript? ...

Generate lighter/darker color in css using javascript

Hi, let say I have #404040 color code. How to generate a new color code which is either lighter or darker by 20% (or given x%)? I need this for generate a hover color in a dynamic site (which color is changing using theme). Therefore it is not possible to use another class or :hover with predefined class. Thanks ...

Using HTML comment tag <!-- --> still relevant around JavaScript code?

Is it still relevant to use HTML comment tag around JavaScript code? I mean <html> <body> <script type="text/javascript"> <!-- document.write("Hello World!"); //--> </script> </body> </html> ...

jQuery: query a $.get() returned string

Hi, How can i query a string i get via $.get? for example, i want form google only the body html: $.get("www.google.com", function(data){ var body = $("body", data).html(); //This doesnt work }); Is it even possible? thanks ...