How to refresh template.dotx?

Javascript question: How do I refresh a window remotely without it being triggered by an event? Ie. I don't want an Onlick, I just want a window.refresh SCRIPT>

  • Javascript question: How do I refresh a window remotely without it being triggered by an event? Ie. I don't want an Onlick, I just want a window.refresh SCRIPT> I know I'm on the right lines with window.refresh(); but how do I specify a target? Thanks so much in advance! I do know a bit of javascript but no enough to choose correct google terminology. I'm trying to write a php script in a remote window that writes to a database then refreshes the main window and closes itself (i have the code for this) cheers.

  • Answer:

    In your calling window (the main window), include the following function:function change(href){ window.location.href = href;} In your remote window, you can simply call opener.change('http://www.google.com');and voilà! Remote window changin' goodness. :)

jwhittlestone at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

Which window is the main window and which window is the target (e.g. is it a frame or a popup)? The proper command to refresh a page is location.reload() or you can use location.reload(true) to force a reload even if nothing was changed. All you need to do is assign it to a target (e.g. in those two previous examples it would reload the window it was run from). To assign it to a popup you would need a handle to a popup, here's how: //open a new window... btw popups suck var handler = open("foo.html", ...); //refresh popup handler.location.reload(true); Now, to force refresh of the popup on a regular basis, you'd need to use the setInterval function. For example, if your popup is generated onload (I'm going to hell I know) then you might use code similar to this: var popupHandler; // handler has global scope, necessary var intervalHandler; //handler for refresh so you can stop it if you want //function to refresh the popup, duh. function refreshPopup() { //you probably want validation or a try catch here in case of popup blockers popupHandler.location.reload(true); } //anonymous function that triggers when the main window finishes loading. Anything in this function will be executed. onload = function () { //open a popup handler = open("foo.html", .....); //set popup to refresh once every 15 seconds intervalHandler = setInterval("refreshPopup",15000); } The same can be done with frames by appending location.reload() to the end of a reference to the appropriate frame. I'd give you an example but frames suck even more than popups and so I've forgotten the syntax. It's something to the effect of top.document.frames["frameName"].location.reload(). Hope that gets you in the right direction.

furtive

Oh, I just reread your question, what you want is this: onload = function () { opener.location.reload(); window.close(); }

furtive

Urm. Ok, still a bit stumped (me=a little bit simple) I have the main window displaying a picture and a button that gives the option for the user to change the pic On clicking the button, a javacript function is called to open a new window that lets the user browse for the picture and upload it to the database upon submitting. Upon submitting in the new window, i want the main page to refresh showing the updated picture. is this possible? cheers Jon

jwhittlestone

I'm assuming you already have the popup code and picture submission code in place. For the purpose of this example, let's assume your upload form submits the image to action.php In action.php you should include something akin to the following:echo '<body onLoad="opener.location.reload();window.close();">';Of course you will probably already have an existing <body> tag, which you would have to modify accordingly. Hope that helps!

PuGZ

Thanks so much, im nearly there i think! ive included this function in my javascript file function refreshopener() { opener.location.reload(); window.close(); } then, i've done this in the html body popup. like i say, i don't want it on an event, just to happen once the server side scripting has done the database funcitons refreshopener(); It doesn't seem to work, surely im on the right track?

jwhittlestone

well, you can't refresh the main window until the submit has been completed, which rules out doing a location.reload() in the onsubmit even handler, so you have to do it on the onload of the popup when it reloads (assuming it submits to itself). Basically, you said you already have a close() to get rid of the popup, so you'll want the opener.location.reload() right before that close(). IRC would be a much better venue for discussing things like this. There are excellent #javascript channels on the undernet and freenode.

furtive

Basically "opener.location.reload();" was the statement i was after and i now know that. thanks to both of you, a real help - i'll try it when i get home as i seem to have buggered up my PHP script here! thanks again.

jwhittlestone

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.