I want to get the selected text from the i-frame, where the source is from another domain.
<html>
<head>
<script>
function getselText()
{
var iframe = document.getElementById("my");
var txt = getIframeSelectionText(iframe);
document.aform.selectedtext.value = txt;
}
function getIframeSelectionText(iframe) {
var win= iframe.contentWindow || iframe.contentDocument.defaultView;
var doc= iframe.contentDocument || win.document || iframe.contentWindow.document;
if (win.getSelection) {
return win.getSelection().toString();
}
else if (doc.selection && doc.selection.createRange) {
return doc.selection.createRange().text;
}
else if (doc.selection) {
return doc.selection.createRange().text;
}
else
{
alert('Error in rendering');
}
}
</script>
</head>
<body>
<iframe id="my" frameborder="1" scrolling="yes" width="800" height="400" src="info.php">
This is I-Frame Content
</iframe>
<input type="button" value="Get selection" onmousedown="getselText()">
<form name=aform >
<textarea name="selectedtext" rows="5" cols="20"></textarea>
</form>
</body>
</html>
This code works well with the source of the i-frame in the same domain. But, I need to get the selected text from the i-frame where the source is from different domain (to which I don't have access to change it).
Example:
<iframe id="my" frameborder="1" scrolling="yes" width="800" height="400" src="http://www.anotherdomain.com">
This is I-Frame Content
</iframe>
Please help me in this.