JavaScript in the <a> tag nested, quote

Here is a simple <a> tag that refers to an exe file. The onClick JavaScript onClick redirects the user to another web page in 3 seconds.

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

So this does not work because there are too many nested quotes.

The first quotation marks "" refer to the onClick function. The second quote '' is for the SetTimeout function. I need third quotes for the window.location function. I tried using "and" but nothing works. The above syntax fails.

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

EDIT:

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

 onClick="setTimeout('window.location=\'/downloading.html\'',3000);return true;" 
+4
source share
2 answers

You need to avoid quotes:

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

You need to avoid double double quotes with backslash.

Here is an example:

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

Source: https://habr.com/ru/post/1312996/


All Articles