-4

I have a tricky situation where one set of rules conflicts with another over specifications of banners.

One spec details that single quotes are not allowed, and the other has a script which is essential to the banner. Without the script, there is no point serving the banner in the first place.

So the question is, is there a way to write this script using only double quotes?

<script>
    document.write('<script src="' + (window.API_URL || 'http://example.com/' + Math.random()) + '"><\/script>');
</script>
Kyle
  • 60,843
  • 27
  • 138
  • 150

1 Answers1

1

Can't you just escape the double quotes that you don't want to terminate the string? \" evaluates to the literal character ".

document.write("<script src=\"" + (window.API_URL || "http://example.com/" + Math.random()) + "\"><\/script>');
Michael
  • 34,340
  • 9
  • 58
  • 100