views:

88

answers:

2

Here is simple <a> tag, which links to an exe file. The onClick JavaScript event redirects the user to another webpage after 3 seconds.

<a href="http://www.example.com/download.exe"
onClick="setTimeout('window.location="/downloading.html"',3000);return true;">
LINK</a>

So it doesn't work because there are too many nested quotes.

The first quotes "" are for the onClick function. The second quotes '' are for the SetTimeout function. I need third quotes for the window.location function. I've tried using both ' and " but none work. The above syntax fails.

I can solve it by refactoring the JavaScript into a function, but there are reasons why I cannot implement that. Is there a solution to this?

EDIT:

The answers below did not quite work, but led me to the correct solution:

onClick="setTimeout('window.location=\'/downloading.html\'',3000);return true;"
+4  A: 

You need to escape the quotes:

<a href="http://www.example.com/download.exe" onClick="setTimeout('window.location=\"/downloading.html\"',3000);return true;">Something</a>
Matt
+3  A: 

You need to escape the inner double quote with backslash.

Here is the example:

<a href="http://www.example.com/download.exe"
onClick="setTimeout('window.location=\"/downloading.html\"',3000);return true;"</a>
Billy