0

I am new to js and wrote the following

<script type='text/javascript'>
function setIframeText() {
var iframe0 = document.getElementById('iframe0');
var iframe0document=iframe0.contentDocument||iframe0.contentWindow.document;
var cookieValue = getCookie('auf_name');
iframe0document.getElementById('jform_title').value = cookieValue;}</script>

So I have a HTML where I have an iframe with the id iframe0 and the textbox in the iframe hast the id jform_title. I want to set the value of the textbox in the iframe out from the parenty document, I tried it with my script and a button but it didn't work. It should change the value to the value of the cookie "auf_name".

Roman C
  • 49,761
  • 33
  • 66
  • 176
user3125470
  • 109
  • 10

2 Answers2

0

You can check this this How to get the body's content of an iframe in Javascript?

Note: Please, always you should check if the solution exists in other post. Well, You should check if you scripts is hosted in same domain, Also review if you don't have restrictions from server, the server could deny your access via scripts to iframes. You can find out to using google chorme debug.

Community
  • 1
  • 1
joseluisq
  • 508
  • 1
  • 7
  • 19
  • I already searched and came to the solution I used above, but I am not sure if I did right with the cookie or maybe something else is the problem – user3125470 Jan 04 '14 at 19:05
  • Well, First check if you script is placed in same domain, Also review if you don't have restrictions from server, the server could deny your access via scripts to iframes. You can find out to using google chorme debug. – joseluisq Jan 04 '14 at 19:10
  • it says reference error getCookie is not defined do i need special libraries for that function, I am not sure how this works in js – user3125470 Jan 04 '14 at 19:15
  • OK it was my fault I didn't define getCookie function. I am new to js and thought its already built in. – user3125470 Jan 04 '14 at 19:24
  • Oh understand, I imagined the getCookie function is not defined ;) Good luck ! – joseluisq Jan 04 '14 at 19:26
0

My friend please make this function and rerun your code and please share with me what are u getting in the alert window

function getCookie(){
alert(cookie_variable);
}
Girish
  • 1,717
  • 1
  • 18
  • 30
  • Thank you I already realized the problem I copied the getCookie function but didn't know that it first needs to be declared. So I copied it from there also and now it works. – user3125470 Jan 04 '14 at 19:41