I need to get the html source of a page from javascript, without jQuery
In my object, I did this :
showPopUp: function() {
//Call method to get Html Src
BLExitIntent.getPageSrc();
alert(BLExitIntent.pageContent);
},
getPageSrc: function(){
var request = new XMLHttpRequest();
request.open('GET', 'page.html', false);
request.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status >= 200 && this.status < 400) {
// Success!
BLExitIntent.pageContent = this.responseText;
} else {
console.log('Page' + 'page.html' + ' not found');
}
}
};
request.send();
request = null;
},
My problem is : when I make a synchronous request, the
alert(BLExitIntent.pageContent);
give the good result but I have the warning about User Experience :
Synchronous XMLHttpRequest outside of workers is in the process of being removed from the web platform as it has detrimental effects to the end user's experience.
But, if I make the same call in an asynchronous way, "BLExitIntent.pageContent" is empty
If there a way to do it?
My call is get the Htlm code of an external page...