Brds
Brds

Reputation: 1075

possible to refresh (not reload) a parent page with javascript?

I have a page that shows images. if a certain record doesn't have an image associated with it yet, I provide the user with a pop-up window link so that they can upload an image. When the user submits the form on the pop-up, it refreshes, uploads the image and then automatically closes. Before the pop-up closes, i want to refresh (not reload) the parent. The reason I don't want to reload is because I'm using post data to dynamically populate the page content. If I reload, all the previous data is lost. I tried to change window.opener.location.reload(true); to window.opener.location.refresh(true); ... but apparently that's not a valid command.

Is there a way to refresh the parent page instead of simply reloading it?

Upvotes: 0

Views: 1712

Answers (2)

amdorra
amdorra

Reputation: 1556

If I understood your question correctly, and made the assumption that you have the image url you want to load inside your page

you can simply create an image tag set its src attribute to the image url and then put it on your page

like this

node = document.createElement('img');
node.setAttribute('src', imageUrl);
list.appendChild(node);

you can see this in action here

Upvotes: 0

TheVillageIdiot
TheVillageIdiot

Reputation: 40507

If you want to show the newly uploaded image, then the best way is to have a function on parent page like:

top.refreshImage = function(url){
    $("#<ID_OF_IMAGE_TAG>").attr("src",url);
    //Or if you are not using jQuery then usual way
    document.getElementById("<ID_OF_IMAGE_TAG>").src=url;
}

Then from dialog, after the image is uploaded call this function:

top.refreshImage("<URL_OF_NEWLY_UPLOADED_IMAGE");

Upvotes: 1

Related Questions