0

I have a button on one asp page which calls a function in a js file "java_s.js"having parameter a and b . like this :

<button id="abc" onclick= "LoadContent(a,b)"></button>

Now there is another asp page which contain an iframe in it and show the content of a html page xyz.html like this :

<iframe src="xyz.html"></iframe>

i had included java_s.js file in it . but the problem is when this LoadContent() function is called it is not able to put the content in the div that are defined in xyz.html . So my problem is how to link this js file with the html file .

RononDex
  • 4,143
  • 22
  • 39
user21
  • 23
  • 2
  • 9
  • 1
    possible duplicate of [Communication between iFrames?](http://stackoverflow.com/questions/16657399/communication-between-iframes) – Quentin Feb 19 '14 at 08:55
  • Did you try this same page first? – Sameera Thilakasiri Feb 19 '14 at 08:56
  • if i include this button inside the iframe i had mentioned above . the content is comming inside the iframe . but this button have to be in different page . or if i include that html page in the page where button is . the whole content comes out of the iframe . – user21 Feb 19 '14 at 09:00

2 Answers2

0

Try this approach:

<iframe id="iframe1" src="xyz.html"></iframe>

js: (assume there is a div with id "foo" in xyz.html)

var foo = document.getElementById('iframe1').contentWindow.document.getElementById("foo");

var div = document.createElement("div");
foo.appendChild(div);

You could also use jQuery, which would require you to write less code.

fabian
  • 642
  • 6
  • 18
0

include jquery library Try to add ID to your iframe object like so:

and in you js file write:

function LoadContent(a,b){
return // a , b args
}

$("#abc").live("click",function(){
$("#any").html(LoadContent(a,b));
});
ADAD.TJ
  • 63
  • 8