Hi! i have a html page with a iframe. I want to be able to select some text from iframe and when i push a button outside the iframe the selected tet shoul be copied in a text field ( the text field is also outside the iframe). I searh for days how to cummunicate between the iframe and parrent - and nothing. I already have a function in javascript wich copies the selected text in a text field (the text field is outside the iframes).
This is the code....
....
<p>Some text outside the iframe.</p>
<iframe name="iframe1" id="iframe1" src="http://www.devittwinery.com/our_wines.html"></iframe>
<form>
<input type="text" name="textbox1" value="" />
<input onclick="copyit(this.form.textbox1)" type="button" value="Copy" name="btnCopy" />
</form>
....
and the javascript function is:
function copyit(theField) {
var selectedText = document.selection;
if (selectedText.type == 'Text') {
var newRange = selectedText.createRange();
theField.focus();
theField.value = newRange.text;
} else {
alert('select a text in the page and then press this button');
}
}
this is the function that works for a text outside the iframeeas. when i want to copy the text from the iframe instead of "var selectedText = document.selection;" i put:
iframe = document.getElementById("iframe1");
var selectText =iframe.contentWindow.selection;
and i have a big error...
Can anyoane help me?... please Thanks