javascript firefox 自動加載iframe 自動調整高寬示例
更新時間:2013年08月27日 15:44:07 作者:
iframe 自動獲取onload高寬以及iframe 自動加載,具體實現如下,感興趣的朋友可以參考下
iframe 自動獲取onload高寬
function AutoResize(iframe)
{
//firefox
if(iframe.contentWindow)
{
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
iframe.width = iframe.contentWindow.document.documentElement.scrollWidth;
}
//IE
else if(iframe.contentDocument) {
iframe.height = iframe.contentDocument.width;
iframe.width = iframe.contentDocument.height;
}
}
iframe 自動加載:
var tdObj = document.getElementById('ifrtd');
tdObj.innerHTML = ' QQ動態(tài)加載中 ... ';
var iframe = document.createElement("iframe");
iframe.src = 'http://www.zbphp.com/';
if (iframe.attachEvent){
//iframe.attachEvent("onload",AutoResize.call(iframe)); #報錯
iframe.attachEvent("onload", function(){
AutoResize(iframe);
});
} else {
//iframe.onload = AutoResize.call(iframe);#報錯不支持
iframe.onload = function(){
AutoResize(iframe);
};
}
tdObj.innerHTML = '';
tdObj.appendChild(iframe);
其實那個iframe.onload這里想寫成iframe.onload = AutoResize.call(iframe);很遺憾,報錯,不支持。
一直不知道javascript 如何進行函數調用。比如遇到 iframe.onload = function(){} 調用函數且有參數的時候,這樣的情況只能這樣寫,而不能像其他程序那樣直接傳參。
以前看過有 apply() call(),但試過都是不支持的。為什么?
復制代碼 代碼如下:
function AutoResize(iframe)
{
//firefox
if(iframe.contentWindow)
{
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
iframe.width = iframe.contentWindow.document.documentElement.scrollWidth;
}
//IE
else if(iframe.contentDocument) {
iframe.height = iframe.contentDocument.width;
iframe.width = iframe.contentDocument.height;
}
}
iframe 自動加載:
復制代碼 代碼如下:
var tdObj = document.getElementById('ifrtd');
tdObj.innerHTML = ' QQ動態(tài)加載中 ... ';
var iframe = document.createElement("iframe");
iframe.src = 'http://www.zbphp.com/';
if (iframe.attachEvent){
//iframe.attachEvent("onload",AutoResize.call(iframe)); #報錯
iframe.attachEvent("onload", function(){
AutoResize(iframe);
});
} else {
//iframe.onload = AutoResize.call(iframe);#報錯不支持
iframe.onload = function(){
AutoResize(iframe);
};
}
tdObj.innerHTML = '';
tdObj.appendChild(iframe);
其實那個iframe.onload這里想寫成iframe.onload = AutoResize.call(iframe);很遺憾,報錯,不支持。
一直不知道javascript 如何進行函數調用。比如遇到 iframe.onload = function(){} 調用函數且有參數的時候,這樣的情況只能這樣寫,而不能像其他程序那樣直接傳參。
以前看過有 apply() call(),但試過都是不支持的。為什么?
相關文章
基于JS如何實現類似QQ好友頭像hover時顯示資料卡的效果(推薦)
通過本文給大家介紹鼠標經過好友列表中的好友頭像時顯示資料卡的效果,非常不錯具有參考借鑒價值,感興趣的朋友一起看下吧2016-06-06JavaScript對象_動力節(jié)點Java學院整理
這篇文章主要為大家詳細介紹了JavaScript對象的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06