For the Love of My Country

Andy Moore's web-development blog: HTML, CSS, JavaScript, Flash (subscribe)
quicklinks: html codes | w3 schools (CSS) | colour codes | archives
blogging at: Star Studded Super Step on politics, abortion, freedom...
Two Identical JavaScripts Running On One Page
Sunday, May 24, 2009, 7:27 AM
Have you ever tried to run two javascripts on one page, but found that they conflict, and either only one works, or neither of them work? I had this problem with two blog sidebar widgets which I made. One widget counts the number of abortions performed worldwide since the page was opened. The other counter counts up the number of women affected by abortion sinice the page was opened. As you would imagine, the two scripts were virtually identical - this caused them to lock up.

I had a shot at renaming various elements within the javascript, but to no avail.

For a while I used a horrible hack - put the javascript for the abortion affects women counter into an iframe, and put that script in another piece of javascript. It worked, but it was ghastly, and frustrating.

Eventually, after skim-reading this useful page, I found that you basically need to make sure everything has a different name, and then you'll be sweet.

Compare the two scripts if you like, for reference.
script one
script two

Joy!

Labels:

Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home
Archives: \April 2007/\June 2007/\September 2007/\August 2008/\September 2008/\October 2008/\December 2008/\February 2009/\March 2009/\May 2009/\July 2009/\August 2009/\September 2009/\October 2009/\November 2009/\December 2009/\January 2010/\February 2010/\March 2010/\August 2010/\September 2010/\December 2010/