I have an iframe in my page and how can i get a the value of t text box in the frame from my parent page on a button click?
here is my code
<div>
<iframe src="test.html" >
<input type=text id="parent_text">
<input type="button">
</div>
here is d test.html
<input type="text" id="frame_text">
thanks
Assuming your iFrame is in the same domain as your OutSystems application you can run Javascript to get the values: var myIFrame = document. getElementById('<Widget.Id>'); //Fetch Inner HTML inside body var contentHTML = myIFrame. contentWindow.
window); When a page is running inside of an iframe, the parent object is different than the window object. You can still access parent from within an iframe even though you can't access anything useful on it.
We can get the value of the text input field using various methods in JavaScript. There is a text value property that can set and return the value of the value attribute of a text field. Also, we can use the jquery val() method inside the script to get or set the value of the text input field.
open or a window inside <iframe> , and that window comes from the same origin, then we have full access to that window. otherwise, if it comes from another origin, then we can't access the content of that window: variables, document, anything.
Something like this:
var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var input = innerDoc.getElementById('frame_text');
First you get the the iframe. Then you get the first valid dom document from inside the iframe.
And finaly get the input box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With