tags:

views:

56

answers:

1

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!!

+1  A: 

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").

David Dorward
I agree with this answer, both technically and philosophically. What you might do is add a GET parameter to your URL to set the div.
Andrew Johnson
Okay, I had a feeling it wouldn't be a good way to do it. Thanks. That's probably what I'll end up doing.
morningface