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=".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;"
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./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;"
Share
Improve this question
edited Jun 16, 2010 at 17:21
soupagain
asked Jun 16, 2010 at 16:41
soupagainsoupagain
1,1335 gold badges16 silver badges32 bronze badges
1
- Can you write your code in here. So it would be easy for people to go through – sushil bharwani Commented Jun 16, 2010 at 16:43
2 Answers
Reset to default 6You need to escape the quotes:
<a href="http://www.example./download.exe" onClick="setTimeout('window.location=\"/downloading.html\"',3000);return true;">Something</a>
You need to escape the inner double quote with backslash.
Here is the example:
<a href="http://www.example./download.exe"
onClick="setTimeout('window.location=\"/downloading.html\"',3000);return true;"</a>