I have a problem. It's AJAX load page, and script tags execution of that page.
.then(response => {
let restr: string = response;
restr = restr.replace(/(<head[^>]*)(?:[^])*?\/head>/ig, '')
.replace(/(<(\/?)body([^>]*?)>)/g, '')
.replace(/(<style[^>]*)(?:[^])*?\/style>/g, '')
.replace(/(<(\/?)html([^>]*?)>)/g, '')
.replace(/(<app-root[^>]*)(?:[^])*?\/app-root>/ig, '')
.replace(/(<\?[\s\S]*?\?>)|(<!DOCTYPE\s+\w+\s+\[[\s\S]*?\]>)|(<!\w[\s\S]*?>)/g, '')
.replace(/href\s*=\s*(?:")/ig, 'href="/#')
.replace(/href\s*=\s*(?:')/ig, "href='/#");
let scripts = restr.match(/\<scr[\s\S]*?ipt>/g);
this.srcfield.nativeElement.innerHTML = '';
scripts.forEach(value => {
var element = document.createElement('script');
var valstr = value.match(/"([^"]+)*"/g)[0]
.replace(/"|'([^"]+)*"|'/g, '')
.replace(/text\/javascript/g, '');
element.src = valstr;
this.srcfield.nativeElement.appendChild(element);
})
this.response = restr;
})
How do you realize, response is answer from server, it's just HTML page provided by text. I make some operation on this page, and product it to current user page, without reloading.
But some tag script doesn't load, because it execute don't by order.
How can i load script tags to correctly
P.S The page which loaded, was generate by YII2 Framework