James Jeffery
James Jeffery

Reputation: 3485

Escaping Problem

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.

Upvotes: 0

Views: 85

Answers (3)

OdinX
OdinX

Reputation: 4211

This works:

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

Upvotes: 0

Paul J
Paul J

Reputation: 1519

Why not just use a meta refresh?

<meta http-equiv="refresh" content="1;url=http://example.com" />

Upvotes: 0

Francisco Soto
Francisco Soto

Reputation: 10392

<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.!

Upvotes: 5

Related Questions