отремонтировал Хром, поломал ИЕ
<script>
window.onload = function () {
// Modal window
var image = document.getElementsByClassName("toModal");
if (image.length) {
//document.body.innerHTML += '<div id="modalDiv"><img id="modalImg"></div>';
let div = document.createElement('div');
div.id = "modalDiv";
document.body.append(div);
let img = document.createElement("img");
img.id = "modalImg";
document.getElementById("modalDiv").appendChild(img);
var modalDiv = document.getElementById("modalDiv");
var modalImg = document.getElementById('modalImg');
for (var i = 0; i < image.length; i++) {
image[i].onclick = function(){
modalDiv.style.display = "block";
modalImg.src = this.src;
var w = window.innerWidth;
var h = window.innerHeight;
var coef = 2;
// смотрим что бы поместились в экран
if (modalImg.naturalWidth*coef > w || modalImg.naturalHeight*coef > h) {
coef = modalImg.naturalWidth*coef / w > modalImg.naturalHeight*coef / h ? w / modalImg.naturalWidth : h / modalImg.naturalHeight;
}
modalImg.style.height = modalImg.naturalHeight*coef + 'px';
modalImg.style.width = modalImg.naturalWidth*coef + 'px';
}
}
modalDiv.onclick = function() {
modalDiv.style.display = "none";
}
}
}
</script>