I am trying to pass a php variable value, through an iframe over to a javascript variable. All files are on my own server and domain.
This is my html file:
<html>
<head>
<?php
$userOutput = "bob";
?>
</head>
<body>
<p id="test123"><?=$userOutput?></p>
</body>
</html>
And in my original page i try to access the information like this:
<iframe id="iframeId" src="http://path/to/file.html"></iframe>
<script>
window.onload = function() {
var iframeDoc = document.getElementById('iframeId').contentWindow.document;
var test = iframeDoc.getElementById('test123').value;
console.log(test);
};
</script>
Now, i do manage to reach my content, and i have tried before to just get the value of some input field i put in my "file.html" with success, but i can't seem to reach the php variable value ("test" shows up as undefined)
$userOutputis, i saved it as say file.php and then the other file where the JS is I saved it as file2.html and all works fine? Are you able to runphpinfo();in your .php file. Just to be sure php is setup as it should be.file.htmlshould befile.phpand file2.html can stay as it is. Anything with php in should have the.phpextension rather than the.htmlunless you're running things like AngularJS