javascript

What is the most efficient way to clone a JavaScript object?

What is the most efficient way to clone a JavaScript object? I've seen: obj = eval(uneval(o)); but that's not cross platform (FF only). I've done (in Mootools 1.2) things like this: obj = JSON.decode(JSON.encode(o)); but question the efficiency. I've also seen recursive copying function, etc. I'm pretty surprised that out-of-the-bo...

What to do when IE's moveToElementText spits out an Invalid Argument exception

We've written a plugin to the Xinha text editor to handle footnotes. You can take a look at: http://www.nicholasbs.com/xinha/examples/Newbie.html In order to handle some problems with the way Webkit and IE handle links at the end of lines (there's no way to use the cursor to get out of the link on the same line) we insert a blank eleme...

jQuery onClick execution

I have this bit of javascript written with jQuery 1.2.5. It's contained inside the main function() of a plugin that I wrote. The plugin is a horizontal gallery scroller very similar to jCarousel. It does alot of auto calculating of widths and determines how many to scroll based on that and the size of the images, which is what all the...

How to line up items of varied length in a resizable space in CSS?

I'd like to line up items approximately like this: item1 item2 i3 longitemname i4 longitemname2 anotheritem i5 Basically items of varying length arranged in a table like structure. The tricky part is the container for these can vary in size and I'd like to fit as many as I can in each row - in other...

Parent.FindControl() not working?

I have a page that has an iframe From one of the pages within the iframe I want to look back and make a panel on the default page invisible because it is overshadowing a popup I tried using Parent.FindControl but it does not seem to be working. I am positive I have the right id in the findcontrol because I used Firebug to inspect the p...

Make a <div> fade away nicely after a given amount of time

What is the best way to make a fade away after a given amount of time (without using some of the javascript libraries available). I'm looking for a very lightweight solution here not requiring a huge javascript library to be send to the browser. ...

Simplest SOAP example using Javascript

What is the simplest SOAP example using Javascript? To be as useful as possible, the answer should: Be functional (in other words actually work) Send at least one parameter that can be set elsewhere in the code Process at least one result value that can be read elsewhere in the code Work with most modern browser versions Be as clear a...

How to convert an "object" into a function in JavaScript?

JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function. How do you do the reverse, and add a function to an "object"? This works: var foo = function() { return 1; }; foo.baz = "qqqq"; At this point, foo() calls the function, and foo.baz...

Max length of send() data param on XMLHttpRequest Post

Is there a documented max to the length of the string data you can use in the send method of an XMLHttpRequest for the major browser implementations? I am running into an issue with a JavaScript XMLHttpRequest Post failing in FireFox 3 when the data is over approx 3k. I was assuming the Post would behave the same as a conventional Form ...

Are Mutexes needed in javascript?

I have seen this link: Implementing Mutual Exclusion in JavaScript. On the other hand, I have read that there are no threads in javascript, but what exactly does that mean? When events occur, where in the code can they interrupt? And if there are no threads in JS, do I need to use mutexes in JS or not? Specifically, I am wondering ab...

How can I select an <img> element programmatically using JavaScript?

I have an <img> in an HTML document that I would like to highlight as though the user had highlighted it using the mouse. Is there a way to do that using JavaScript? I only need it to work in Mozilla, but any and all information is welcome. EDIT: The reason I want to select the image is actually not so that it appears highlighted, but ...

How do I make an Ajax.Autocompleter perform a request without typing?

I'm using scriptaculous's Ajax.Autocompleter for a search with different filters. http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter The filters are requiring me to pass data into the autocompleter dynamically, which I've successfully learned to do from the following link. http://www.simpltry.com/2007/01/30/ajaxautoco...

Adding New Element to Text Substring

Say I have the following string: "I am the most foo h4ck3r ever!!" I'm trying to write a makeSpecial(foo) function where the foo substring would be wrapped in a new span element, resulting in: "I am the most <span class="special">foo></span> h4ck3r ever!!" BeautifulSoup seemed like the way to go, but I haven't been able to make it ...

What's a good tool to screen-scrape with Javascript support?

Is there a good test suite or tool set that can automate website navigation -- with Javascript support -- and collect the HTML from the pages? Of course I can scrape straight HTML with BeautifulSoup. But this does me no good for sites that require Javascript. :) ...

Help with some simple javascript cookie misconceptions

im using the following code for setting/getting deleting cookies: function get_cookie(cookie_name) { var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)'); if (results) return ( decodeURI(results[2]) ); else return null; } function set_cookie(name, value, exp_y, exp_m, exp_d, path, domai...

How to determine the OS path separator in JavaScript?

How can I tell in JavaScript what path separator is used in the OS where the script is runnning? ...

Monitoring a server-side process on Rails application using AJAX XMLHttpRequest

I'm using the following in the web page but can't get a response from the server while it's processing <script type="text/javascript"> <!-- function updateProgress() { //alert('Hello'); new Ajax.Request('/fmfiles/progress_monitor', { parameters: 'authenticity_token=' + encodeURIComponent(AUTH_TOKEN), onS...

How to efficiently count the number of keys/properties of an object in JavaScript?

What's the fastest way to count the number of keys/properties of an object? It it possible to do this without iterating over the object? i.e. without doing var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) count++; Firefox provides a magic __count__ property, but this isn't available in other implementations. ...

Python library for rendering HTML and javascript

Is there any python module for rendering a HTML page with javascript and get back a DOM object? I want to parse a page which generates almost all of its content using javascript. ...

How to implement unobtrusive javascript with dynamic content generation?

Hey, I write a lot of dynamically generated content ( developing under PHP ) and I use jQuery to add extra flexibility and functionality to my projects. Thing is that it's rather hard to add JavaScript in an unobtrusive manner. Here's an example: You have to generate a random number of DIV elements each with different functionality tr...