This question has already been answered:
- Blank page after document.write 1 reply
How to replace:
document.write('<img src="' + window.Pic + 'Nickelback.jpg" height="311" width="400">'); So that the page is not erased?
This question has already been answered:
How to replace:
document.write('<img src="' + window.Pic + 'Nickelback.jpg" height="311" width="400">'); So that the page is not erased?
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
All options are correct: both appendChild, innerHTML, and insertBefore, but there is one BUT ... The browser interprets the code from top to bottom. When it reaches your javascript code, the required element does not exist yet . Try this:
window.onload = function(){//Эта функция выполнится тогда, когда документ полностью загрузится var img = document.createElement('img'); img.src = window.Pic + 'Nickelback.jpg'; img.height = 311; img.width = 400; document.body.appendChild(img); } document.write always clears the page. this is his normal behavior. use dom-tree manipulations. Looking ahead, I’ll say that dom elements have an innerHTML property that might be useful to you.
document.appendChild('<img src="' + window.Pic + 'Nickelback.jpg" height="311" width="400">') document.getElementById('element').appendChild(/* ваш элемент */) also read about insertBefore , innerHTML , insertAdjacentHTML
Source: https://ru.stackoverflow.com/questions/327811/
All Articles