Confusing question...
In echo i have blank page.. if i set innerHTML="some text"; - it works. Why it's not working with image? If i directly goes to https://domain.com/adv/banner.jpg it will open image...
echo'
  <div id="yabanner"></div>
  <script>
  yaGetBanner();
  function yaGetBanner()
  {
    var el = document.getElementById("yabanner");
    el.innerHTML="<img src=\'https://domain.com/adv/banner.jpg\' width=\'400px\' height=\'150px\'>";
  }
  </script>
  ';
                Image doesn't display inside innerHTML.
To set the value of innerHTML property, you use this syntax: element. innerHTML = newHTML; The setting will replace the existing content of an element with the new content.
Setting innerHTML is synchronous, as are most changes you can make to the DOM.
You need double quotes for the img attribute too, and then you need the backslashes. So your code would look like:
echo '
<div id="yabanner"></div>
<script>
yaGetBanner();
function yaGetBanner()
{
   var el = document.getElementById("yabanner");
   el.innerHTML="<img src=\"http://placehold.it/350x350\" width=\"400px\" height=\"150px\">";
}
</script>';
Also note that you have
bannerandadvin the name of your image URL. Adblockers will block these images or addinlinestyling to yourimgattributes containing that image.
I hope this help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With