javascript

Namespacing technique in JavaScript, recommended? performant? issues to be aware of?

In a project I am working on I am structuring my code as follows MyLib = { AField:0, ASubNamespace:{ AnotherField:"value", AClass:function(param) { this.classField = param; this.classFunction = function(){ // stuff } } }, AnotherClass:functio...

Better alternative to an iframe?

Hi. I have a page with an iframe to feature the contents of the clicked tab. There are 3 tabs and 1 iframe. The sources of the contents relating to each tab clicked are formatted and coded in other html & css files. What is another alternative to using an iframe, because I noticed that when the tab is clicked, it still shows the white b...

Importing javascript file multiple times on same page

I have a javascript file called pendingAjaxCallsCounter.js with a variable "var pendingAjaxCalls" which is incremented/decremented when various methods in the js file are called. Separately, I have created an automated testing app which checks that the pendingAjaxCalls has a value of 0 before interacting with any page. I'm wondering, if...

Calendar Selection

Greetings, Might be having a brain fart this morning, but I need a way to execute some JavaScript at the conclusion of an operation taking place inside an ASP .NET Ajax Update Panel. How can this be accomplished? Thanks, jason Updated based on responses: I was not entirely clear, as both initial answers were correct given what I was ...

How to track changes on jqGrid columns/layout/order?

Hello, I have a jqGrid that can be sorted by different columns both in ascending and descending order. Columns may be added or removed, and the order of the columns may be changed too. I need to detect when any of these properties have changed, in order to save the users preference. Is there a way to catch these events? I've been loo...

Set default content for target div

Hi. If this is my code, how do i set page1.html to show by default on page load? Thanks in advance. <head>     <title>Test</title>     <meta http-equiv="content-type" content="text/html; charset=UTF-8">     <script type="text/javascript">     function swapContent(targetID, url) {         var target = document.getElementById(targetI...

Color Logic Algorithm

We are building a sports application and would like to incorporate team colors in various portions of the app. Now each team can be represented using several different colors. What I would like to do is to perform a check to verify whether the two team colors are within a certain range of each other, so that I do not display two si...

Gears File Drag & Drop: getDragData doesnt refresh

Hello all, I've been implementing a Gears-powered fileupload mechanism for our app. It works great except for one small bug. When I drag files onto the window, the function call desktop.getDragData() properly gives me the list of files dragged over the first time. However, subsequent drops with calls to this function give me the origi...

JavaScript event sequence

Some events in JavaScript fire before others. For example, with an input element, the keydown and keypress events fire first. Then, if the return value from those was not false, the input.value is updated. Then, the keyup event fires. Is there a web site where I can find a comprehensive list of all events and the order in which they are...

"Too much recursion" error when using intanceof over typeof?

I was making a function to convert all dates in an object to strings and when I used the following function I got a error in FF "too much recursion". (It also fails in IE and chrome) function datesToString(obj) { if (obj instanceof Object) { if (obj instanceof Date) { obj = "this part does not ma...

Accessing document's javascript variable from firefox extension

is it possible for Firefox extension (toolbar) to access document's variables? detailed explanation follows.. loaded document: <script type="text/javascript"> var variableForExtension = 'something'; </script> extension: var win = window.top.getBrowser().selectedBrowser.contentWindow; alert(win.variableForExtension); // undefined i...

Function not working on Vista

I have this JavaScript function which is working in all the machines I tried except the one that is running on Vista. I am calling this function onload. what do you think is wrong with this one. function isePad() { var epad; epad = window.document.esCapture1.ConnectedDevice; if (!epad) { alert('Sorry epad either is ...

CSS Cross-browser opacity from Javascript

I want to turn down the opacity on an element when a user performs an action. The current code I have is: document.getElementById('MyOpaqueElement').style.opacity = 0.3; // There are checks in the real code for NULL, etc. This works on Firefox, Safari, etc. IE8 has different ideas about opacity. I have read a couple of articles but ...

Can we capture an event when user presses X on the browser window?

is there a way differentiate between refresh and close in Javascript? i use window.onbeforeunload now which works great in IE. To void this being called anywhere but close, i set a flag on EVERY button ...this seems like a difficult, hacky solution, but after searching for hours on google, it was the best i could find. Isn't there an o...

If statement for Jquery / Javascript

Here's what I'm trying to achieve: I have a div that switches between fixed and absolute positioning depending on the scroll position. I have an example that works but I noticed that it's a little slow because it constantly changes the position on each and every pixel of scroll. So I thought that adding an additional if statement (as ki...

Capture user response when using window.onbeforeunload

Is there a way to capture whether the user clicked OK or CANCEL? I need to do something ONLY if the user is leaving the page.... ...

How Do You Implement an Editable Grid Control in Html/JavaScript that Binds to a Collection of Java Objects?

Consider a simple POJO Java Object: class MyObj { String a, b; Integer c; } My application executes a Struts action and sets a Collection of these on the Http Request: request.setAttribute("myObjects", getCollectionOfMyObj()); The action then forwards to a JSP page, and this is where my questions centres: What is the simplest...

Mercator longitude and latitude calculations to x and y on a cropped map (of the UK)

Hi I have this image: http://imgur.com/99tSz.png. A map of the UK (not including Southern Ireland). I have successfully managed to get a latitude and longitude and plot it onto this map by taking the leftmost longitude and rightmost longitude of the UK and using them to work out where to put the point on the map. This is the code (for...

Compress an XML file with javascript?

I have found the DIY Map.. an excellent map tool if you are ever looking for one. Aside from how fantastic it is... the associated XML file can get fairly large (it contains map setting, country names etc). I was wondering if it were possible to compress it and have javascript uncompress it on the users side.... There is a lot of repeti...

Getting real source code with javascript?

OK I don't use js enough to know, but is there a way to get the real source code of the page with it? document.body.innerHTML for example gives some kind of "fixed up" version where malformed tags have been removed. I'm guessing using XMLHttpRequest on the original page might work, but seems kind of stupid. ...