(using jquery or just js) Is it possible to add script to an iframe and then add an element to trigger it? This adds the script but it gives me an error in Chrome saying that the function is undefined.
//create element
var cloned = $("<input type='button'/>")
cloned.attr('onclick', "alertUser()");
var parent = $("#parent");
var iframe = $('<iframe />').attr("id", "rbm_pu");
parent.append(iframe);
var frame = $("#rbm_pu").contents();
frame.find("body").append(cloned);
frame.find('body').append("<script type='text/JavaScript'>function alertUser(){alert('hello');}</script>");
It appears in there but says that alertUser()
is undefined. Any ideas? Thanks