获取iframe内容IE下的延时 (转载)
2011-06-23 13:59 爱研究源码的javaer 阅读(358) 评论(0) 编辑 收藏 举报function iframeOnload(id,func)
{
function isIe(){
return
navigator.appName == 'Netscape' ? false : true;
}
function getDocument(id)
{
var iframe =
document.getElementById(id);
switch(isIe())
{
case false:
//ff
var a = iframe.contentDocument;
return a;
case true:
//ie
var a = iframe.contentWindow.document;
return a;
}
}
function band()
{
var iframe =
document.getElementById(id);
switch(isIe())
{
case false:
//ff
iframe.onload = function(){
func(getDocument(id));
}
return iframe;
break;
case true: //ie
iframe.onreadystatechange = function(){
if(this.readyState ==
'complete'){
setTimeout(function (){
func(getDocument(id));
},1000);//由于IE下有延时所以来一个setTimeout
}
}
return iframe;
break;
}
}
return
band(id);
}
function search_Google()
{
var
obj=document.getElementById('shopname');
if(obj.value.trim()==''){
alert('你必须输入商品名称!');
return false;
}else{
var keyword =
$('#shopname').val();
}
fg =
'http://192.168.81.106/pcnp/g.php?keyword='+encodeURI(keyword);
iframeOnload('googleiframe',function(so){
var callstr = so.body.innerHTML;
//document.getElementById('googlediv').innerHTML=callstr+'ss';
search_360buy(callstr);
});
window.open (fg, 'googleiframe');
}
//记录代码,不作说明http://hi.baidu.com/caixudong/blog/item/026cf490fb23fa84a977a4fc.html