0

I have this

console.log(document.getElementsByClassName('value')[0].innerHTML);

Is there possibility to get this value from other page (without manually open this page)?


Can i get all value from page? Now when i use it i see only first value

W.Dud
  • 5
  • 2
  • 5

3 Answers3

1

Is there possibility to get this value from other page (without manually open this page)?

Without opening that page no, only from the current window (I assume this is what you mean when you're saying "page").

Can i get all value from page? Now when i use it i see only first value

Yes, document.getElementsByClassName('value') returns an array i.e exactly what you need. In your example you're just selecting the first element from the array, that's why you see only the first value.

Try this:

var all=document.getElementsByClassName('value');

for(var i=0;i<all.length;i++){
 console.log(all[i].innerHTML);
}

....

W.Dud
  • 5
  • 2
  • 5
lore01
  • 26
  • 2
1

Yes it's possible.

Create an AJAX request to get the website you need to extract values from. This StackOverflow answer provides dependency-free example code.

You can then parse the request using DOMParser, which is supported by all major browsers.

Community
  • 1
  • 1
Tobias Mühl
  • 1,788
  • 1
  • 18
  • 30
0

Set your value to local storage :

Set value to local storage localStorage.setItem('key', 'value');

Get value from another page localStorage.getItem('key');

Set your data

var data = document.getElementsByClassName('value')[0].innerHTML;
localStorage.setItem('value', data);

Get it from another page

localStorage.getItem('value');

Documentation : https://developer.mozilla.org/en/docs/Web/API/Window/localStorage

Otherwise you can use sessionStorage, Web SQL, IndexedDB & Cookies.

0xdw
  • 3,755
  • 2
  • 25
  • 40