Substitution of variable into link with many interior quotes - how to escape correctly

42 views Asked by At

I am setting up a link to Adobe's Aviary web app, which requires input in the following format:

<a href="#" onclick="return launchEditor('editableimage1', 
'http://www.mywebsite.com/IMAGE.jpg');">Edit!</a>

I need to substitute a variable name for the IMAGE.jpg part of this, and I have tried to do this using the following code. Since the visual cues tell me that the variable name isn't being interpreted I already know this will fail, but I can't see how to express it properly. Sorry, very new to Javascript so hope someone can kindly help. Here's my code:

<script>
var imgNamePassed = sessionStorage.getItem('imgName');
console.log("imgName", imgNamePassed);
</script>

<a href='#' onclick="return launchEditor('editableimage1','http://www.mywebsite.com/ + imgNamePassed + "');&quot; />"LINK TEXT</a>
1

There are 1 answers

0
Stanislav On BEST ANSWER

Fix it to:

<a href='#' onclick="return launchEditor('editableimage1','http://www.mywebsite.com/' + imgNamePassed);"/>LINK TEXT</a>

Example: JSFiddle