How to change a div's innerHTML after redirecting?
I am trying to change the innerHTML of a开发者_运维技巧 div on the page that I am loading.
This is my JavaScript code:
function redirect(titleName){
window.location = "pageToLoad.php";
document.getElementById("title").innerHTML = titleName;
}
It doesn't seem to be working, please help me!!
The execution life of a script extends only for as long as the page it is running in lives.
If you want to access the DOM of one document from a script running in another, then the other page has to hang around. This means you either have to use frames or open popups.
Neither of these is a good idea. You should rethink what you are trying to achieve and find a better approach (which will probably be "Just change the title of the page you are linking to in the source of that page").
精彩评论