refer this
Page1
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var response = xhr.responseText;
document.getElementById('ajax').innerHTML = response;
setTimeout(function () {
var script = document.getElementById('ajax').getElementsByTagName('script')[0];
if (script) {
var js = script.innerText;
eval(js);
}
}, 100)
}
};
xhr.open('get', 'htmlpage2.html');
function startAjax() {
xhr.send();
document.getElementById('hide_button').style.display = 'none';
}
</script>
</head>
<body>
<button id='hide_button' onclick='startAjax()'>Start</button>
<div id='ajax'></div>
</body>
</html>
Page2
<script>
alert('js is executed');
</script>
<h1>Radom text</h1>