javascript

How can you determine if a css class exists with Javascript?

Is there a way to determine whether or not a css class exists using JavaScript? ...

preg_match_all JS equivalent?

Is there an equivalent of PHP's preg_match_all in Javascript? If not, what would be the best way to get all matches of a regular expression into an array? I'm willing to use any JS library to make it easier. ...

How can I use a multiline value for an HTML tag attribute? (i.e. how do I escape newline?)

How do I include a newline in an HTML tag attribute? For example: <a href="somepage.html" onclick="javascript: foo('This is a multiline string. This is the part after the newline.')">some link</a> Edit: Sorry, bad example, what if the tag happened to not be in javascript, say: <sometag someattr="This is a multiline string. This is...

Is it possible to optimize/shrink images before uploading?

I am working on a web application that will deal with many image uploads. Its quite likely that the users will be in areas with slow internet connections and I'm hoping to save them upload time by compressing the images before uploading. I have seen that Aurigma Image Uploader achieves this using a java applet or active x but it's expe...

Setting a cookie before Javascript Redirection

Hello, I have a Rails app where I set a set a session variable the moment a user lands on my site with the referer and the page they hit. Additionally, I have Google Optimizer sending traffic from my homepage to various landing pages. The problem is that I think Google Optimizer is sending users away before the cookie is set. Is t...

registerClientScriptBlock in custom handler?

I'm using a custom control in ASP.NET that handles file uploading for me. The control has a handler in the code-behind using something like this: Protected Sub UploadFileComplete(ByVal sender As Object, ByVal e As UploadControl.FileUploadCompleteEventArgs) Handles UploadControl.FileUploadComplete Within that sub, I post back to the se...

clean links to PHP-generated javascript and css

Background: When generating HTML content with PHP or any such thing, it is possible to encapsulate links to javascript and css inside tags without actually having to include the CSS and JS "in-line" with the rest of the content. All you have to do is create a link to the file. Example: {script type="text/javascript" src="./js/fooscr...

How can I call an anonymous function (stored in string) with an argument in JavaScript?

I have the following situation in JavaScript: <a onclick="handleClick(this, {onSuccess : 'function() { alert(\'test\') }'});">Click</a> The handleClick function receives the second argument as a object with a onSuccess property containing the function definition... How do I call the onSuccess function (which is stored as string) -and...

Is it safe to have tell Apache server to handle .js and .css files as PHP?

Based on an answer I saw in this question: Link I'm wondering, is this a safe thing to do? Suppose I implement this and a page gets requested that has a couple of JS and CSS files linked to it. Are the textfiles simply sent or does the server first parse them? Don't have a server to test it right now. Also, is this a common method of ...

SEO & Ajax

I'm experimenting with building sites dynamically on the client side, through javascript + a json content server, the js retrieves the content, and builds the page client-side. Now, the content won't be indexed by google this way, is there a work around for this? like having a crawler version and a user version? Or having some sort of st...

What is my script src URL?

Is there a simple and reliable way to determine the URL of the currently-executing JavaScript file (inside a web page)? My only thought on this is to scan the DOM for all the script src attributes to find how the current file was referenced and then figure out the absolute URL by applying it to document.location. Anyone have other idea...

Getting content of a script file using Javascript

Hi guys I have the following script element in my web page: <script src="default.js" type="text/javascript"></script> Using JavaScript, I want to be able to retrieve the content of the script file. I know I could use a ajax request to get the data but then I am getting something from the server that I already have locally. So what ...

Javascript game; slowing down and freezing! How to solve it?

Hi, I'm starting to program a javascript tower defense; so far i have the movement of the minions over a trajectory. But I have a very big trouble, the game suddenly freezes for a couple of seconds. I'm guessing that is the garbage collector doing its job, any ideas on how i can solve this will be very good since i plan on adding a lot m...

Ajax Highscores security

I'm creating a tower-defense game in javascript and want to have a high score and other multiplayer interactions. Probably have a couple of players start the game at the same time and tell them how fast the other guys are going and that kind of stuff. I don't know how flash games send their scores or events to make sure the information ...

How to clear the contents of the openwysiwyg editor?

I am using the openwysiwyg editor in my webpage. I want to clear the contents of it. I have used $('#report').val(''); but that doesn't clear it. The editor creates an iframe and updates the contents there, syncing as it goes. How would I go about clearing it? ...

Silverlight and JavaScript Communication

I'm having a dandy of a time getting Silverlight and JavaScript to communicate with each other. In the page.xaml.cs file, I marked the class as ScriptableType and two methods with ScriptableMember. I then declared: HtmlPage.RegisterScriptableObject("Page", this); When I attempt to invoke either method, I get obj.Content.Page is und...

dynamic building of a list

Hi, I was wonder how I could get input from a user, then display that input underneath on a new line along with any previous input. I was wondering if this could be done in either HTML or Javascript ...

Can i use a function name in my jquery plugin parameters?

I am creating a form validation plugin for jQuery and would like it to call a function once the form has been successfully validated. The plugin will have a default callback function, but I would like to modify this through the options parameter. Unfortunately what i have (below) does not work. Any ideas? (function($){ $.fn.extend(...

How can I stop an onclick event from firing for parent element when child is clicked?

Hi, I'm having two issues with onclick events, they are somewhat similar so I'll ask them both here. First: I have a checkbox in a div. The input has an onchange function and the div has an onclick function. <div onclick="doSomething()"> <input type="checkbox" onchange="doSomethingElse()" /> </div> The problem is when I check/...

Change the magnification [ZOOM] level of a div with contents inside it

Hi, I have a main div with a fixed width for which the overflow is set to hidden. Inside that there is a content div which can have variable width depending on the number of its contents. Each content has an image and some text. There may be 100 s of contents. I have a scrollbar for changing the magnification level and a scrollbar for vi...