javascript

Is there a way to determine that the browser window was closed?

How is it possible to identify that the browser's close button was clicked? ...

What is the best way to include the icon in the target region of clickable text?

I am currently using the following javascript to create an expanding menu: http://demo.raibledesigns.com/struts-menu/scripts/menuExpandable.js.src Currently, only the hyperlink text is clickable. What is the best way to have the icon next to the text respond to the click? ...

Class Variables in Javascript

I'm having a bit of trouble trying to get class variables to work in javascript. I thought that I understood the prototype inheritance model, but obviously not. I assumed that since prototypes will be shared between objects then so will their variables. This is why this bit of code confuses me. What is the correct way to implement...

Find the number of <td>s in a <tr> without using id or name

How do you calculate the number of <td> elements in a particular <tr>? I didn't specify id or name to access directly, we have to use the document.getElementsByTagName concept. ...

Why can I use a function before it's defined in Javascript?

This code always work, and across browsers. function fooCheck(){ alert(internalFoo()); return internalFoo(); function internalFoo(){ return true; } } fooCheck(); I could not find a single reference to why it should work, though. I first saw this in John Resig's presentation note, but it just mentioned it. There's no explanatio...

How to specify a relative path for the jsUnit-ant-script?

JsUnit provides an ant-script with the target 'standalone_test'. This target uses the property url to identify the HTML-site, that executes the tests. These site is checked in, so that everyone should be able after a checkout to execute this tests. This works, but the url-proprty must be set to an absolute path, like file:///home/user/pr...

rollover effect using Jquery

Would you please help me in making a rollover effect using jquery, what i want to do is when someone hover over any of the menu items the text slide down and disappear and a picture slides from the top down to the center (e.g. you could see this effect here panda as you can see the picture slide down from the top but the text does not sl...

Strange behaviour opening pop-up window in Internet Explorer

I have the following JavaScript code to pop up a window in Internet Explorer. The code is executed from a page within a Microsoft CRM modal dialog box. (RequestID is a string that is always the same in the test system - at the moment it contains "abcdefg" - without the quotes). var cancelUrl = "CancelRequest.aspx?RequestID=" + RequestID...

Escaping dilemma in Javascript.

Hi everyone, I have the following var id='123'; newDiv.innerHTML = "<a href=\"#\" onclick=\" TestFunction('"+id+"', false);\"></a>"; Which renders <a href="#" onclick="return Testfunction('123',false);"></a> in my HTML. The problem I have is that I wish to take the call to the method TestFunction, and use as a string parameter in m...

Good Javascript Combo Box replacement for combo boxes with tons of elements?

I have a page where my combo box has hundreds of elements which makes it very hard to pick the one item I want. Is there a good Javascript replacement that would do better than <select id="field-component" name="field_component"> <option selected="selected">1</option><option>2</option>... </select> Is there somethin...

Can I close the iPhone browser using JavaScript

In the iPhone is there a way I can use JavaScript to close the browser and return to the home screen? After the last page a wizard I am calling out to another iPhone app (ex: maps) and I do NOT what the user to come back to the browser screen when they are done. My backup plan is to have a "Complete" page but that is not the best experie...

How can I update meta refresh from javascript when using asynchronous calls?

I have a system that uses a meta refresh to a logout page, which cleans up after idle users. (Don't worry, the server also times out the session) I started doing some operations via ajax (not really xml, but that's beside the point). I can run javascript returned from the async request, so I'm wondering if it's possible to reset the m...

javscript - Array.map and parseInt

From the Mozilla Dev Site: [1,4,9].map(Math.sqrt) will yield: [1,2,3] Why then does this: ['1','2','3'].map(parseInt) yield this: [1, NaN, NaN] I have tested in Firefox 3.0.1 and Chrome 0.3 and just as a disclaimer, I know this is not cross-browser functionality. (No IE) [edit] I found out that the following will accomplish...

List Object's built-in Properties

Is there a way for me to loop over a Javascript Object's built-in properties? for...in gets me close to where I want to go, but "A for...in loop does not iterate over built-in properties." ...

Why won't this event listener work?

$('input[type=checkbox]').unbind().click(function(e){ $(this).attr('checked', true) return false; }); I NEED to return false because I have an event on its parent and I don't want to trigger that. It just WON'T check that checkbox :| Already it drive me insane. I think I used this before on another project and I had no problems ...

Javascript onHover event

Is there a canonical way to set up a JS onHover event with the existing onmouseover, onmouseout and some kind of timers? Or just any method to fire an arbitrary function if and only if user has hovered over element for certain amount of time. ...

javascript problem

i have a php script and i'm using ajax with it . i have a textarea form connect with the ajax class the problem when i pass a text like ( &some text ) the function return an empty text ,i geuess that i have a problem with (&) , what is the problem here ? here the javascript function function sendFormData(idForm, dataSource, divID, if...

Determine if an element has a CSS class with jQuery

I'm working with jQuery and looking to see if there is an easy way to determine if the element has a specific CSS class associated with it. I have the id of the element, and the CSS class that I'm looking for. I just need to be able to, in an if statement, do a comparison based on the existence of that class on the element. ...

How can I determine if an image has loaded, using Javascript/jQuery?

I'm writing some Javascript to resize the large image to fit into the user's browser window. (I don't control the size of the source images unfortunately.) So something like this would be in the HTML: <img id="photo" src="a_really_big_file.jpg" alt="this is some alt text" title="this is some title text" /> Is there a ...

How to get cursor position in textarea?

How do you get the cursor position in text area using JavaScript? For example: This is| a text This should return 7. How would you get it to return the strings surrounding the cursor/selection? eg: 'This is', '', ' a text' If the word "is" is highlighted, then it would return 'This ', 'is', ' a text' ...