tags:

views:

39

answers:

3

How can escape quotes for use in HTML? My line of code is:

<body onload="setTimeout('window.location='http://somepage.com'', 1000)">

As you can see in the current example, there are two ', and a " being used. How can I escape them for the above to work?

The onload contents are set dynamically for a system I am working on @ work.

+5  A: 
<body onload="setTimeout(function () { window.location='http://somepage.com'; }, 1000)">

That should do your trick. You may want to to take a look at http://en.wikipedia.org/wiki/Unobtrusive_JavaScript, it could make your javascript cleaner.

Cheers.!

Francisco Soto
Nice answer; I like the format of "here's the answer to your actual question, and here's a suggestion to improve your overall approach" a lot.
JacobM
A: 

Why not just use a meta refresh?

<meta http-equiv="refresh" content="1;url=http://example.com" />
paulj
Meta refreshes are deprecated. They will probably still work for a while though.
Andy E
A: 

This works:

<body onload="setTimeout('window.location=\'http://google.com\'', 1000)">
Chief17