TellyKNeasuss
Illuminator
- Joined
- Oct 4, 2006
- Messages
- 3,781
I've run into a problem when using location.href in Javascript to load a new page into the browser window. The problem is that script execution does not wait for the new page to be loaded, but instead processing continues. This means that if I do something like
location.href = "new_page.html";
var mainDiv = document.getElementById("mainContent");
var paragraph = document.createElement("p");
paragraph.innerHTML = "blah blah blah";
mainDiv.appendChild(paragraph);
to add more verbiage once new_page.html gets loaded, the new verbiage will instead get written to the window while the current page is still loaded and then be over-written along with the rest of the current page once new_page.html actually gets loaded. Any ideas about how to get around this problem?
location.href = "new_page.html";
var mainDiv = document.getElementById("mainContent");
var paragraph = document.createElement("p");
paragraph.innerHTML = "blah blah blah";
mainDiv.appendChild(paragraph);
to add more verbiage once new_page.html gets loaded, the new verbiage will instead get written to the window while the current page is still loaded and then be over-written along with the rest of the current page once new_page.html actually gets loaded. Any ideas about how to get around this problem?