How to get a javascript variable from another page?

Asked

Viewed 48 times

0

For example, on a page you have a script tag like this:

<script>var X = "variável que quero pegar";</script>

How could I get this variable "X" on another page just with the url of it and carry to current page? Consider that the page can be external url server.

  • Variables cannot go from one page to another. If they are from the same site you can use localstorage, cookies and other features.

  • What if you could read the text of the page with Javascript and return the text? for example, read what is between "<script>Content...</script>" and return that content?

  • With PHP it would be possible

  • I want to avoid the use of the server, I will try with Xmlhttprequest, if not I will resort to it itself, thanks for the suggestion

  • Dude, what you could do is send a request to the page in question, use a regex or an XML parser to take the value from inside the script tag and then give it a eval in this value. But that is braba’s gambs, would only use in last of last case.

  • I understand kkk, but I will try with PHP or Javascript

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.