javascript

Onload can fire early when using jsp dynamic includes?

When a jsp page includes jsp dynamic includes... <jsp:include page=”filename.jsp” /> ...is it possible that the document onload event (or prototype's dom:loaded event) could get fired too early? (i.e. before the included filename.jsp has fully loaded) The reason I suspect this may be the case is that the included file is compiled s...

Google Analytics Widget Tracking

Hello, I have a form that is generated on a customer's website (lets say customer.com) with javascript that a user fills out and it sends to my site (app.com). I would like to be able to provide information to the customer such as how effective their AdWords campaign was and what search engines users used to end up filling out the form....

Jquery Bugs?? Long decimal number after two numbers multiply...

Hi all I am working on a shopping site and I am trying to calculate the subtotal of products. I got my price from a array and quantity from getJSON response array. Two of them multiply comes to my subtotal. I can change the quantity and it will comes out different subtotal. However,when I change the quantity to certain number, the...

How to implement this feature in javascript ? Make uncertain , divorce, the wife say!

In the Javascript, could I define a class, the class itself can also when a function call, similar to the index, such as: function A() { } var a=new A(); var v=a(); //Use ordinary/like Javascript function use ...

Creating a simple JQuery tooltip?

Has anybody here got any experience in creating simple tooptips using JQuery? I have created a table: <tr id="mon_Section"> <td id="day_Title">Monday</td>` <td id="mon_Row" onmousemove="calculate_Time(event)"></td> </tr>` the function "calculate_Time" will be called and this gets the X position of the mouse cursor and fro...

ASP.NET MVC submitting json array to controller as regular post request (nonajax)

All the examples of json I can find online only show how to submit json arrays w/ the jquery command $.ajax(). I'm submitting some data from a custom user control as a json array. I was wondering if it's possible to submit a json array as a regular post request to the server (like a normal form) so the browser renders the page returned...

typeof === "undefined" vs. != null

I often see JavaScript code which checks for undefined parameters etc. this way: if (typeof input !== "undefined") { // do stuff } This seems kind of wasteful, since it involves both a type lookup and a string comparison, not to mention its verbosity. It's needed because 'undefined' could be renamed, though. My question is: How is...

Best placement for javascript in Asp.net MVC app that heavily uses partial views

What is the best place for javascript that is specific to a partial view? For example, if I have a partial view (loaded via ajax call) with some divs and I want to turn those divs into an accordian, would it be better put the $("#section").accordion() in script tags inside of the partial view, or in a .js file in the function that retri...

How do I compute a variable in JavaScript if and only if it is used?

This is what I'm doing right now. var foo = function() { var x = someComplicatedComputationThatMayTakeMoreTime(); this.foo = function() { return x; }; return x; } It works but only if foo is called as a function like so foo(); But what if I want to call it as a normal variable with a value? I could modify the code to be var ...

Javascript fine grain performance tweaking

I have been writing my first jQuery plugin and struggling to find a means to time how long different pieces of code take to run. I can use firebug and console.time/profile. However, it seems that because my code executes so fast I get no results with profile and with time it spits out 0ms. (http://stackoverflow.com/questions/2690697/fir...

In Google Chrome, how do I bring an existing popup window to the front using javascript from the parent window?

I would like to have a button on a web page with the following behavior: On the first click, open a pop-up. On later clicks, if the pop-up is still open, just bring it to the front. If not, re-open. The below code works in Firefox (Mac & Windows), Safari (Mac & Windows), and IE8. (I have not yet tested IE6 or IE7.) However, in Goo...

Why this jquery plugin giving error in IE but working fine in firefox?

This page work in Firefox but not in IE7 http://www.robwalshonline.com/demos/randomImageDemo/randomImage_plugin.html This is page of plugin http://www.robwalshonline.com/posts/jquery-plugin-random-image-on-page-load/ How to get this work in all browser FF, safari, chrome and IE 6, 7 ,8 ...

JavaScript, iPhone: Repeat Action while Holding Button

I am working on a website which I would like to work on iPhones, however I want it so they can tap and hold a button and have it continue firing the onclick event. I got it to work in other browsers, but the iPhone is the only one that will need to hold down the button. Is there a way to repeat a function when holding down the button? Th...

Is String.concat slower than Array approach to join strings

Strings in JavaScript are immutable. Across the web and here on Stack Overflow as well, I came across the Array approach to concatenate strings: var a = []; a.push(arg1,arg,2....); console.log(a.join('')); I know that this approach is better than the simple console.log(arg1 + arg2 +.....); for reasons of skipping creating interme...

Is it possible to run JavaScript before any image loads?

Is it possible to run JavaScript before any image loads? Is this default behavior? Dom, script, IMG load? ...

How to add url in onclick function?

I have the code new_element.innerHTML ="<a href='#'><img src='"+imagePath+"' alt='' title='' width='466' onclick='addWidget('"+url+"');' height='165'></a>"; which will call the function addWidget: function addWidget(url) { alert(url); var main= document.getElementById('mainwidget'); main.innerHTML = "<iframe src='"+url+"' alig...

Accessing "Public" methods from "Private" methods in javascript class

Is there a way to call "public" javascript functions from "private" ones within a class? Check out the class below: function Class() { this.publicMethod = function() { alert("hello"); } privateMethod = function() { publicMethod(); } this.test = function() { privateMethod(); ...

Is there some way to "nice" my JavaScript execution?

I'd like to run some calculations in a browser window, but I don't want it to slow the client computer down for user interaction, especially for single core machines. Is there some way to adjust the nice level of my executing JavaScript so that it will execute as fast as possible without detracting from the responsiveness of the machine...

Chrome's loading indicator keeps spinning during XMLHttpRequest

I'm writing an AJAX web app that uses Comet/Long Polling to keep the web page up to date, and I noticed in Chrome, it treats the page as if it's always loading (icon for the tab keeps spinning). I thought this was normal for Google Chrome + Ajax because even Google Wave had this behaviour. Well today I noticed that Google Wave no longe...

How can I use Perl to scrape a website that reveals its content with JavaScript?

I need to write a Perl script to scrape a website. The website can only be scraped with JavaScript, and the user is on Windows. I got some way with Win32::IE::Mechanize on my work machine, which has IE6, but then I moved to my netbook which has IE8, and can't even get as far as fetching a simple page. Is Win32::IE::Mechanize up to d...