| Domik942 | 
			16.01.2020 23:29 | 
		 
		 
		
		 
		
		
		
		
		
	Цитата: 
	
	
		
			 
			
				
					Сообщение от рони
					(Сообщение 518696)
				 
				обработка события ставится позднее чем само событие, всё загружено уже, события onload не будет. 
вам дали ссылку на решение  
			
			 
		 | 
	 
	 
 Я только сейчас обратил внимание что на IE 11 не работает. Можно вас попросить подправить код чтобы на 11й версии IE тоже корректно работало ? 
 
<html>
<head>
    <meta http-equiv=content-type content="text/html;charset=UTF-8" />
    <title>test js page</title>
</head>
<body>
<div>the 1 tag</div>
<div>the 2 tag</div>
<div>the 3 tag</div>
<script>
    var testHtml = '<html><head><title>second page</title></head><body><p>test script</p>'+
        '<script>\n' +
        'alert("Hello IE ?");' +
        '<\/script>'+
        '<div>the 7 tag</div><div>the 8 tag</div><div>the 9 tag</div></body></html>';
    var parser = new DOMParser();
    var doc = parser.parseFromString(testHtml, 'text/html');
    var htmlOld = document.querySelector('html');
    var htmlNew = doc.querySelector('html');
    document.replaceChild(htmlNew, htmlOld);
    [...document.querySelectorAll('script')].reduce((promise, el) => {
        return promise.then(() => new Promise((resolve, reject) => {
            var s = document.createElement('script');
            if (el.text) {
                s.text = el.text;
                resolve();
            } else {
                s.onload = resolve;
                s.src = el.src;
            }
            el.parentNode.replaceChild(s, el);
        }))
    }, Promise.resolve());
</script>
<div>the 4 tag</div>
<div>the 5 tag</div>
<div>the 6 tag</div>
</body>
</html>
 
	 |