0

I want to insert text pragmatically in to the text area not in my page. I have loaded a page via iframe and loaded page has textarea.and this 2 pages have different domains not same. I want to paste a text to it. Actually I want to add text no matter paste or type or what ever text should appear in text-area.i can manually click textarea and focus it ,but insert text pragmatically I have added a picture for proper understand. I not sure about possibility. But if impossible are there any alternative ways to achieve this.

this is java-script code i tried

function incert_text() {
  var x = document.getElementById("myframe");
  var y = (x.contentWindow || x.contentDocument);
  if (y.document)y = y.document;
  y.document.getElementById("textarea").value="this is incerted text";
}

this pic will help to properly understand my question

  • post your html code and what have you tried to achieve this. – abc123 Dec 29 '13 at 05:55
  • Please POST code you have tried. – Gopal Joshi Dec 29 '13 at 05:55
  • This is not possible on the client due to same origin restrictions. You would need to load the iframe url on your server and fill in the field there or on the client now it comes from the same domain – mplungjan Dec 29 '13 at 06:07
  • possible duplicate of [jQuery cross domain iframe scripting](http://stackoverflow.com/questions/3083112/jquery-cross-domain-iframe-scripting) – mplungjan Dec 29 '13 at 06:43

3 Answers3

0

Is the iframe you are loading ona different domain? or is it your own iframe?

If it is your own, content, you may be able to use this answer How to interact with the content of an iframe using js or jQuery

If it is not from your own domain, I don't believe you can populate the content of the textarea unless the owner of the site has enabled populating the field via a url query or something similar.

Community
  • 1
  • 1
pedalpete
  • 21,076
  • 45
  • 128
  • 239
  • It is quite obviously not the same domain if you look at the drawing – mplungjan Dec 29 '13 at 06:10
  • not same domain ..and any way to paste something i can click manually textarea and focus it .i want only something like paste –  Dec 29 '13 at 06:13
  • It means that if you fetch the content of the site using PHP and render its content on you own server, this way when you open the site in the iframe, all permissions will be allowed to you but sometimes the content won't be rendered properly. I hope you get the idea – Talha Masood Dec 29 '13 at 09:02
0

One thing you have to be sure about is that you can't just change the content of the IFrame that comes from another domain. This is so not-allowed by the browser security.

I had the same problem some months ago and I did search a lot. It turns out I could come up with no viable solution.

I posted the problem on stackoverflow and here is that question => Cross-Domain Iframe Drag Drop

Some of the Questions here that might give you a jump start are:

jQuery cross domain iframe scripting

One way around to this can be proxying the page onto your server and then serving it into your frame. This is the way I used but the accuracy is less.

Community
  • 1
  • 1
Talha Masood
  • 993
  • 1
  • 7
  • 22
-1

Of course, you will need to set the id on your textArea, and you will need an event handler which does the following:

document.getElementById("myTextArea").value = "Some new value";

JohnC
  • 61
  • 4