I am looking to load javascript files into an iframe with jQuery, but it seems the way I am doing it, inspecting the DOM they are there, but they act as if they are in the parent. Here is some of the code:
somejsfile.js:
function createDraggable(draggableId){
if (jQuery.isFunction(jQuery.fn.draggable)) {
jQuery('#'+draggableId,fPage).draggable({
containment: '#contentArea',
iframeFix: true,
start: function() {
dragStart();
},
drag: function() {
dragHappening(draggableId);
},
stop: function() {
dragEnd(draggableId);
}
});
} else {
setTimeout(function(){createDraggable(draggableId)},100);
}
}
var fPage = $("#contentFrame").contents();
createDraggable(someElementId);
parent.js:
function loadJS(filepath,w) {
if (!$("script[src*='"+filepath+"']",w).length) {
$("head",w).append('<script type="text/javascript" src="'+filepath+'"></script>');
}
}
var fPage = $("#contentFrame").contents();
loadJS('jquery.min.js',fPage);
loadJS('jquery.ui.min.js',fPage);
loadJS('jquery.ui.draggable.min.js',fPage);
loadJS('somejsfile.js',fPage);
Now in somejsfile.js, jQuery('#'+draggableId,fPage).draggable({
works, but jQuery('#'+draggableId).draggable({
doesn't, which leads me to believe that it is not really loading in the iframe. When I look in firebug, I see those scripts in the head of the iframe, but I see the draggable function in the main window jQuery, which I didn't load it there.
The reason I don't want it in the main window is that it doesn't work properly as it jumps away from the object when selected and when clicked it stays selected to drag until you click again.