jeudi 2 avril 2020

Javascript Execution Problems in a Single Page Webapp

I've been trying to design a single page webapp (a game) that will load different HTML documents dynamically into a single webpage.

I'm using pure Javascript (no libraries) and have used XMLhttprequest to download HTML files and display them on-the-fly on a single webpage. This all works great except for the Javascript.

As my Javascript has no way of knowing which dynamic document is loaded at any one time all my scripts are trying to run and it's causing a great deal of errors where scripts are trying to access elements that are not there on the page.

I need to be able to download and run Javascript files on the fly or I need to be able to detect which HTML document I am displaying and activate only the relevant Javascript code.

Does anyone know a solution to my problem or has any better ideas?

Thanks Barry




Aucun commentaire:

Enregistrer un commentaire