iframe外面的js不能調用裡面的dom,只能通過調用裡面的js方法來調用。
iframe外面的js調用裡面的js方法:通過iframe的name.裡面的js方法名調用。
初始化外面的jq:
$(function(){
outiframe.init();
);
outiframe = {
init : function(){
//方法內容,如調用iframe裡面的方法
iframe的nane.ineriframe.inermethod1();
},
method : function(){
//方法內容
}
}iframe裡面的jq:
ineriframe = {//相當於命名空間
inermethod1 : function(){
//方法內容
},
inermethod2 : function(){
//方法內容
}
}
附上iframe的模板:
<iframe width=800 height=500 frameborder=0 scrolling=auto src=""></iframe>
再附上js獲取根目錄的方法:
/**
* 獲取項目根路徑
*
* @returns
*/
function getRootpath() {
var ctx = window.location.pathname;
var rootPath = ctx.substring(0, ctx.substr(1).indexOf('/') + 1);
return rootPath;
}