For example in the following javascript code if you use single quotes to open document.getElementById('code').value =
You'll reach a problem at window.open
where you cannot use single quotes, to open it. That would close the getElementById
and break the code. You also cannot use double quotes, because if double quotes are used you'll run into the same issue when putting quotes around newwindow
. Are there ways around this?
function genorateCode() {
var account = document.getElementById("account").value;
var url = document.getElementById("url").value;
document.getElementById('code').value = '<link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet" type="text/css"><a href="' + url + '" ' + ' onclick="window.open("' + url + '", "newwindow", "width=400,height=500"); return false;">' + '<div class="button"><img src="https://s15.postimg.org/mfpd2ki8r/icon.png" width="16">@' + account + '</div></a>';
}
(this is all put into a text area, so users can use the 'generated' code)
<textarea readonly id="code"></textarea>