1

To reload/refresh a page from another page using JavaScript. (A page, which is already opened in the browser. I need to refresh it (not open again) from another page.)

I refer a lot, but i can't get the exact answer i want.

How to refresh another page using javascript without opening the same page in a new tab

I referred this page. But it has a parent and child page. But i need to refresh a unrelated page from another page. Is this possible?

If so, give me some suggestion.

Explanation of my actual project:

There is a pageA from that using Ajax i called some other page(inside a div of pageA). Then by clicking a link in that div (present in page called from Ajax), it will open a pageB in new tab in the same browser. in that page, when user clicks a button, It will call another page, in that page i do a table update. After that update, pageA should be refreshed. This is the actual project what i have to do.

Community
  • 1
  • 1
user3763227
  • 292
  • 2
  • 15
  • 1
    Y this down-vote?? If you think that this is a simple question, just help me or give some reference? or give a comment y u down-voted this. – user3763227 Feb 16 '15 at 16:42
  • Do you have control of both pages (can you deploy code to them both)? – Sean Vieira Feb 16 '15 at 16:48
  • 1
    Are they in the same domain? The downvote is probably because the question is unclear. – putvande Feb 16 '15 at 16:48
  • @putvande yes. same domain, but A,B,C are 3 pages consider (I need to refresh pageA from pageC), so i mentioned as not parent-child page. A->B and then using javascript to C. – user3763227 Feb 16 '15 at 16:50
  • @putvande oh.. ok thank you.. for mentioning the reason. If possible edit my question. based on my above comment , actually i dont know how to explain it. – user3763227 Feb 16 '15 at 16:51
  • @SeanVieira yeah there is a control, check my comment to `putvande` – user3763227 Feb 16 '15 at 16:53
  • Maybe http://stackoverflow.com/questions/3203530/accessing-the-content-of-other-tabs-in-browser gives you an answer. – putvande Feb 16 '15 at 16:53
  • @putvande But, not actually it answers my need. A page, which is already opened in the browser. I need to refresh it (not open again) from another page. – user3763227 Feb 16 '15 at 17:00

2 Answers2

3

Assuming this is in the same browser and the same domain a simple way is as follows (pseudo code)

Page A -> controller
Page B -> page to be refreshed.

The steps are:-

Page A Calls a Javascript function (via button press for example) that writes a value of 'update: true' to local storage.

Page B has a loop of 500ms that checks this value in local storage - when it sees 'update: true' it sets it back to false and then refreshes itself.

These are all simple things to look-up how to do but if you get stuck just let me know.

Oh and same principle applies on different browsers (i.e. if Page A opened in chrome, Page B opened in Firefox) - just that instead of local storage you use a server and store the state to DB / a file.

Below is a quick example - open the two pages in different tabs then click 'refresh' in the controller apge - you will notice the 'page to be refreshed' page refreshes.

GrahamTheDev
  • 22,724
  • 2
  • 32
  • 64
  • My code is too complicated than you assume. let me explain. There is a pageA from that using Ajax i called some other page(inside a div of pageA). Then by clicking a link in that div (present in page called from Ajax), it will open a pageB in new tab in the same browser. in that page, when user clicks a button, It will call another page, in that page i do a table update. After that update, pageA should be refreshed. This is the actual project what i have to do. – user3763227 Feb 16 '15 at 17:23
  • It would be better, if you suggest something based on my project idea what i mentioned above. Thank you. – user3763227 Feb 16 '15 at 17:24
  • The principle I have given you does not care how many pages you have or what order - all it requires is the flag for update to be set to true and the loop checking for that flag on the page you want to update. – GrahamTheDev Feb 16 '15 at 17:26
  • But i'm not so clear of how to check the table update in a page. please clarify me. I'm using PHP/Mysql – user3763227 Feb 16 '15 at 17:27
  • So on page A - you have a loop checking localStorage for the flag=TRUE, on your page with the table you have javascript set on the table's update function that sets the flag=TRUE when you update, the loop on Page A will pick up on this cheange and will refresh. – GrahamTheDev Feb 16 '15 at 17:27
  • But, there is lots of users online right. It (Button click) may vary for each and every one. Is this possible to have a flag for each users,is the button clicked? – user3763227 Feb 16 '15 at 17:34
  • this uses LOCALstorage so each computer wont care / know about others. If you use the server option then you need to assign a userID to each person and listen out for it. – GrahamTheDev Feb 16 '15 at 17:38
  • updated answer - hopefully you will get how simple it actually is from this example - just replace 'alert' with `location.refresh();` – GrahamTheDev Feb 16 '15 at 17:40
  • 1
    No need to poll - simply listen for the [`storage` event](http://diveintohtml5.info/storage.html#storage-event) in window A. – Sean Vieira Feb 16 '15 at 17:47
  • very true - however I was showing the principle for if he uses server way of doing it - there is also the option of using websockets depending on browser support to get instantaneous updates or for true cross-browserness (yes I just created a word) you could even use cookies to achieve the same effect - nice suggestion though – GrahamTheDev Feb 16 '15 at 18:01
  • @GrahamRitchie its working thank you. But there is a click event in your code. But i need to execute that javascript without any event. that only i'm trying. – user3763227 Feb 16 '15 at 18:27
0

first of find frames(or div) which you want to reload for example

enter code here

var myframe=parent.frames['frameName'];

then

myframe.location.href=myframe.location.href;

i hope it will work well. in my case it work fine. thakns &BR