0

is it possible to write a javascript to access the elements (knowing their id) in another open window? I want to refresh the page and read some elements' contents.

arashtrip
  • 3
  • 4
  • are you talking about child window? – Deepak Kumar Jul 30 '18 at 12:16
  • Possible duplicate of [Accessing the content of other tabs in browser](https://stackoverflow.com/questions/3203530/accessing-the-content-of-other-tabs-in-browser) - [Using JQuery to Access a New Window's DOM](https://stackoverflow.com/questions/7788480/using-jquery-to-access-a-new-windows-dom) – Ferus7 Jul 30 '18 at 12:17

1 Answers1

0

You can totally use sessionStorage ! Here is the Documentation

If user direct to next page in same tab, sessionStorage can easily save you data and reuse in next page.

// set in page A
window.sessionStorage.setItem('youdata', 'youdata');
// or window.sessionStorage['youdata'] = 'youdata';

// get in page B
var youdata = window.sessionStorage.getItem('youdata');
// or var youdata = window.sessionStorage['youdata'];

That's it! very simple!

If you'll open a new tab, you can use localStorage. Here Is the Documentation

The usage of localStorage is like the way of sessionStorage.

While do saving information for other pages, these two method only need browsers' support.

Sneh
  • 25
  • 2
  • 7
  • thanks but how can I specify the other window? I cannot see anywhere to specify a window title or a url. – arashtrip Jul 30 '18 at 12:28
  • it will be helpful if you provide some code or idea so we can identify the problem or what u already tried – Sneh Jul 30 '18 at 12:35
  • the session storage can save your data irrespective of windows or url it will stored on a variable on session which you can use on any window or any url within the server – Sneh Jul 30 '18 at 12:37
  • I dont have any code at the moment. But what I could is going to do is to read an element from Page B (which is open in a different tab or window, for example assume I am going to read an element from Yahoo.com) and then refresh that page (Yahoo.com) every couple of minutes to recheck the element. – arashtrip Jul 30 '18 at 14:32