-1

I am Adel and I am creating a gaming app that works with PHP, js, and HTML, now what I want is a way to get a text from div with the id 'value1' inside an iframe with the id 'ServerData' in js.

This file is stored locally in my program that runs php, js, and html files:

<html>
<head></head>
<body>
<iframe src="http://website.com/file.php">
<div id="value1">
AnText
</div>
</iframe>
<script>
  the script 
</script>
</body>
</html>
7
  • Is the iframe in the same domain as you page? Browser will not allow you to do anything with the iframe if it is from the different domain Commented Aug 26, 2019 at 11:54
  • it's from a different domain, because the file that needs to get the data is stored locally Commented Aug 26, 2019 at 11:59
  • You can not access the iframe content then, the same origin policy prevents that. Commented Aug 26, 2019 at 12:04
  • but my program allows that because it's just for my website Commented Aug 26, 2019 at 12:08
  • Try : var value = document.getElementById("value1").innerText Commented Aug 26, 2019 at 12:10

1 Answer 1

0

You can use textContent:

 var textDiv = document.getElementById("value1").textContent;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.