I am using an outside API that allows me to send extra parameters inside the image src
value, like so
<img src="myImage.jpg?resize=width[scrW]">
The problem is that I don't know what the width variable(scrW) is until I start loading the page. I use <script> var scrW = window.innerHtml </script>
to get the width I need.
I tried using
<script>
document.write('<img src="myImage.jpg?resize=width['+window.innerHtml+']">')
</script>
but the problem with that is that document.write
displays everything in text until the document is ready (or reaches </body>
). And that just looks tacky.
My question is: How can I append/prepend JS variables to src
attribut values during the page rendering?