vendredi 16 août 2019

How to nest quotes in JS event listener for HTML element?

I want to create an image element that, when clicked, opens a blank browser window with a specified background:

<img src="http://example/image1.jpg" onclick="var w=window.open('','_blank');w.document.body.style.backgroundColor='url("http://example/image2.jpg")'">

However, I cannot get the above to work using either ", ', or \xXX (hex) for url("http://example/image1.jpg"), since both " and ' are already used for quoting in outer scope.

What to do?




Aucun commentaire:

Enregistrer un commentaire