2
<iframe src="test.html" id="iframe" ></iframe>
</br>
<input type="button" value="Start" onclick="get()">
</br>
<input id="xtext" type="text">

for example (test.html) contains this text :

<td class=\"datatable-cell\">61.00%<\/td>

When I press the Start button, I want to fetch the value (61.00%), and place it in the textinput

*Note that the value in the example (61.00%) is variable

Greetings :)

4 Answers 4

2

You can get 61.00% by

const iframe = document.getElementById('iframe').contentWindow;
const value = iframe.document.getElementsByClassName('datatable-cell')[0].innerText;

If you want to change it, just change value.

Sign up to request clarification or add additional context in comments.

1 Comment

Ninja'd by 20 seconds :D
1

Try this:

const iframe = document.getElementByID("iframe").contentWindow;

let text = iframe.document.querySelector(".datatable-cell").innerHTML;

Though, beware of scripting attacks, if you don't trust the iframe content.

Comments

0

With JQuery

$('.xtext')[0].click(function() {   
  $('#iframe').contents().$(".datatable-cell").html();
 }

Comments

0

this my code :

<iframe src="http://www.golanpal.com/ahmad/test.txt" id="iframe" ></iframe>
</br>
<input type="button" value="Start" onclick="get()">
</br>
<input id="xtext" type="text">

<script language="JavaScript" type="text/javascript">
function get() {

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?????????????

}
</script>

in The text.txt file contains a value of (61.00%)

i want When press the Start button, I want to fetch the value (61.00%), and place it in the textinput (xtext)

*Note that the value in the example (61.00%) is variable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.