请教:如果判断当前页面含有框架,并且判断框架的URL状态或者是框架名称?? 判断当前页面内嵌有框架??并且可以捕捉到框架的name属性最好是能捕捉到框架的URL,如果捕捉不到URL,能捕捉到框架的name属性也行。再或者是捕捉到框架页内的DOM。最好是能给出jQuery的写法,感谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script src="js/jquery-1.3.2.js" type="text/javascript"> </script><script>window.onload = function(){ $("iframe,frame").each( function(){ alert($(this).attr("name")); alert($(this).attr("src")); } ) }</script><iframe name="xx" src=""></iframe> 要获得iframe的DOM的话,首先iframe和主页要是同源的可以:$("#frame_id").contents().find("selector") 你好,iframe和主页要是同源,同源是什么意思?URL还是什么?我之前用$("#frame_id").contents().find("selector")来获取,好像不太稳定,有时候出现有时候不出现,是不是就是同源的原因?? 同源的意思时要在同一个域下面,比如你实际页面地址在google.com的域名下面。框架嵌套页面在baidu.com域名下面,你就无法获得框架内部元素的操作权限。用$("#frame_id").contents().find("selector")来获取数据,要在frame的onload函数中执行,你还可以把jquery的ready方法用在这里更早的执行JS。例子:test.html:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>临时框架对象</title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script type="text/javascript">$(document).ready(function(){ //临时框架对象: function FrameObj(src){ this.strSrc = src; //前缀URL this.datestr = new Date()-0+""; this.strFullSrc = this.strSrc + "?" + this.datestr; //总是获取最新版本的数据 this.strFrameName = "Frame"+this.datestr; this.CreateFrame(); } FrameObj.prototype.CreateFrame = function(){ var strsrc = this.strFullSrc||""; $("body").append('<iframe id="'+this.strFrameName+'" name="'+this.strFrameName+'" scrolling="no" src="'+strsrc+'" frameborder="0" style="display:none;"></iframe>'); return this; }; FrameObj.prototype.Ready = function(func){ var j_this = $("#"+this.strFrameName+""); j_this.load(function(){ j_this.contents().find(document).ready(function(){ if($.isFunction(func)){ func(j_this.contents()); } }); }); return this; }; FrameObj.prototype.Remove = function(){ $("#"+this.strFrameName+"").remove(); } //用法: var newFrame = new FrameObj("index.html"); newFrame.Ready(function(jobj){ alert(jobj.find("body").html()); });});</script></head><body>临时框架对象</body></html>index.html:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>index</title></head><body>这是index.html的内容</body></html> dtree如何点击父节点标题内容,展开子节点内容 百分求jQuery+PHP ajax上传文件简单可用的代码.....0点到4点 试了n次都不行... 问个问题 ASP中如何调用js文件中的函数 谁知道怎么屏蔽iframe里面的右键,要兼容IE和FF的!谢谢 请问下拉框、和列表框怎么用CSS美化? 请问用JS如何获得服务器时间! 恶毒的网站代码,谁有办法,请拔刀相助!万谢! 有个父子页面控件交互的问题呀,,,,等ing......... 谁有办法? 利用webbrowse如何实现批量打印 动态生成div的问题
<script src="js/jquery-1.3.2.js" type="text/javascript"> </script>
<script>
window.onload = function(){
$("iframe,frame").each(
function(){
alert($(this).attr("name"));
alert($(this).attr("src"));
}
)
}
</script>
<iframe name="xx" src=""></iframe>
可以:
$("#frame_id").contents().find("selector")
你好,iframe和主页要是同源,同源是什么意思?URL还是什么?我之前用$("#frame_id").contents().find("selector")来获取,好像不太稳定,有时候出现有时候不出现,是不是就是同源的原因??
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>临时框架对象</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//临时框架对象:
function FrameObj(src){
this.strSrc = src; //前缀URL
this.datestr = new Date()-0+"";
this.strFullSrc = this.strSrc + "?" + this.datestr; //总是获取最新版本的数据
this.strFrameName = "Frame"+this.datestr;
this.CreateFrame();
}
FrameObj.prototype.CreateFrame = function(){
var strsrc = this.strFullSrc||"";
$("body").append('<iframe id="'+this.strFrameName+'" name="'+this.strFrameName+'" scrolling="no" src="'+strsrc+'" frameborder="0" style="display:none;"></iframe>');
return this;
};
FrameObj.prototype.Ready = function(func){
var j_this = $("#"+this.strFrameName+"");
j_this.load(function(){
j_this.contents().find(document).ready(function(){
if($.isFunction(func)){
func(j_this.contents());
}
});
});
return this;
};
FrameObj.prototype.Remove = function(){
$("#"+this.strFrameName+"").remove();
}
//用法:
var newFrame = new FrameObj("index.html");
newFrame.Ready(function(jobj){
alert(jobj.find("body").html());
});
});
</script>
</head><body>
临时框架对象
</body>
</html>
index.html:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
</head><body>
这是index.html的内容
</body>
</html>