我花了几个小时阅读javascript书籍,模式和查看stackoverflow问题,但我坚持在动态加载到iframe
Goal 点击一个按钮,(1)ajax发布到 temp.php
的数据(例如src,height,width,id) . (2) temp.php
设置iframe并返回相应的html . (3)Javascript预装数据 .
这是我到目前为止的相应代码
(1)
$.ajax({
type:"POST",
data:{
'src':"target.php",
'frame_height':$(".mydiv").height(),
'frame_width':$(".mydiv").width()
},
url:"temp.php",
success:function (inHtml) {
loadConversation(inHtml,
我已经将POST变量加载到相应的php变量中 . (2)
<iframe id="myTestFrame" src="<?php echo $src; ?>" width="<?php echo $width; ?>"
height="<?php echo $height; ?>" frameborder="0">
<p>Your browser does not support iframes.</p>
(3) $('.mydiv').prepend(inHtml);
请假设语法正确完成 .
target.php
确实运行了一个初始化滚动插件的简单javascript代码:
$(function () {
var Scroll = (function () {
var init = function () {
$("#content-1").mCustomScrollbar({});
$(".inner_content").mCustomScrollbar({autoDraggerLength:true});
$(".output a[rel~='_mCS_1_scrollTo']").click(function (e) {
e.preventDefault();
$("#content-1").mCustomScrollbar("scrollTo", $(this).attr("href"));
});
};
return { init:init };
})();
Scroll.init();
});
现在发生的事情是,我可以直接从网络服务器调用temp.php,它将正确加载 .
但是一旦从主站点调用它 - 它就会中断(以及“未定义”引导)
我已经完成了相同的iframe帖子,然后用另一个带有插件的php页面动态更新src,它工作正常(点击,ajax post,prepend(html),我完全丢失) . 主站点在jquery UI的标签界面中运行它,但我认为这没有任何区别 - 到目前为止我发现的是,如果我在init中插入一个简单的'alert(document.height)'函数,警报框将包含0,所以我认为javascript在iframe完成加载之前运行 - 但Firebug显示NET中的Response HTML非常好并且代码相当短 . (脚本放在最后一个右括号之前)