-3

I want to refresh the page having url such as:

http://www.abcde.com:81/abcdefg/?_task=abcd&_id=691677786529eea6822deb&_action=show

from another page. That another page having button & form tag as :

echo '<form action="compose.php?r=w" method="post" name="addrbook">';
echo '<input type="submit" name="addr" class="buttons"  value="Use Add"/> ';
echo '</form>';

I want to refresh above already opened window.

Parag
  • 29
  • 1
  • 2
  • 7
  • That's not going to be simple. You'll need to open the page you want to refresh later on with `window.open`. see http://stackoverflow.com/questions/3950620/javascript-cross-window-interaction – mb21 Dec 04 '13 at 09:27
  • is the mentioned URL page is a window popup? if yes then `window.location.reload()` should work, just get reference of that window – HRK Dec 04 '13 at 09:31
  • But that page is already opened & if I'll try to open the page & then reload, It's not possible because "id" in url gets changed. – Parag Dec 04 '13 at 09:34
  • @HRK: Mentioned url page is not a window popup. – Parag Dec 04 '13 at 09:35
  • @Parag if you didn't open the page you want to reload _from_ the page with the button on it - you can't do what you're asking. Explaining why you'd want to do that might allow a more appropriate solution to be proposed. – AD7six Dec 04 '13 at 10:32
  • I want to run javascript on that page, such as when submit button is pressed, that page is closed & www.abcde.com:81/abcdefg/?_task=abcd.......... is refreshed so that javascript will be run. – Parag Dec 04 '13 at 12:51

3 Answers3

1

In javascript make a global variable win. make win equal window.open when you open the new page. The submit button will preform win.location.refresh() which will refresh the page. I believe this only works on the same domain though.

var win;

$('.openOtherPageClass').click(function(){
    win = window.open('http://www.abcde.com:81/abcdefg/?_task=abcd&_id=691677786529eea6822deb&_action=show');
});

$('input[name="addr"]').click(function(){
    win.location.refresh();
});
Adam Merrifield
  • 10,307
  • 4
  • 41
  • 58
  • 1
    @Parag I have updated it so that b.php is the url you requested. Also This will **ONLY** work if the page that you are opening is on the same domain as the page you opened it from. If they are not the same domain then there is no way to do this. Browsers will not allow you to access any `window.location` property from domains that are not exactly the same as the one you are on. – Adam Merrifield Dec 04 '13 at 15:10
  • Domain is same Adam, & how can I provide this javascript code to submit button? I mean Can I call a function in input tag? – Parag Dec 05 '13 at 13:07
  • This also Not working Adam.... – Parag Dec 05 '13 at 13:33
0

I would have included the page in an Iframe (inline frame). That way you can reload the page without complications:

<input type="button" value="Reload Page" onClick="document.location.reload(true)">
<iframe src="http://www.abcde.com:81/abcdefg/?_task=abcd&_id=691677786529eea6822deb&_action=show"></iframe>

(When using JavaScript buttons, you don't need a <form> tag.)

This solution also works across domains!

Peter
  • 2,874
  • 2
  • 31
  • 42
  • If it's in an iframe why reload the page instead of the iframe? -1 as the question isn't _about_ an iframe. – AD7six Dec 04 '13 at 09:46
  • @AD7six: Reloading just the iframe is problematic if it is across domains. Also, it would make the code quite a bit more complex. The question isn't about an iframe, it's about reloading a page. It was never said this could not be done with an iframe! – Peter Dec 04 '13 at 10:19
  • what's problematic about changing the url of an iframe, or deleting it and recreating it? Or alternatively: the question asked talks about reloading a different browser window, what you've proposed is well different with different (unmentioned/unexplained) problems. – AD7six Dec 04 '13 at 10:29
  • It loads www.abcde.com:81.... page on compose.php. I want to refresh www.abcde.com:81.... on submit. – Parag Dec 04 '13 at 12:33
0

Try this:

<input type="button" value="Reload Page" onClick="history.go(0)">

or

<input type="button" value="Reload Page" onClick="window.location.href=window.location.href">

or

location.reload(true);
Prateek
  • 6,785
  • 2
  • 24
  • 37