JQuery对iframe页面的操作

一个简单的设置iframe高度和iframe刷新

 <div id="frameDiv">
	<iframe	id="mainFrame" style="width:100%; height:100%" frameborder="0" scrolling="auto"> </iframe>
 </div>

function init(){	 
	//获取父页面高度
	var height=parent.document.body.clientHeight;
	var frameDiv=document.getElementById("frameDiv");
	//设置div高度
	frameDiv.style.height=height-230; 
}

function getFrameSrc(){
	//刷新计划内容,增加random防止浏览器读取缓存
	var src=context+"jsp/index?id="+id+"&random="+Math.random();
	var mainiframe =document.getElementById("mainFrame");
	mainiframe.src = src;
}
引申内容:

<iframe src="1.htm"name="ifrmname" id="ifrmid"></iframe>

方案一:用iframe的name属性定位
<input type="button"name="Button" value="Button"
οnclick="document.frames('ifrmname').location.reload()">
  或
<input type="button"name="Button" value="Button"
οnclick="document.all.ifrmname.document.location.reload()">

方案二:用iframe的id属性定位
<input type="button"name="Button" value="Button"
οnclick="ifrmid.window.location.reload()">

终极方案:当iframe的src为其它网站地址(跨域操作时)
<input type="button"name="Button" value="Button"
οnclick="window.open(document.all.ifrmname.src,'ifrmname','')">

代码如下:<inputtype=button value=刷新οnclick="history.go(0)">
代码如下:<inputtype=button value=刷新οnclick="location.reload()">
代码如下:<inputtype=button value=刷新οnclick="location=location">
代码如下:<inputtype=button value=刷新οnclick="window.navigate(location)">
代码如下:<inputtype=button value=刷新οnclick="location.replace(location)">

下面这三种我就不知道该怎么用了,就把代码放在下面吧,哪位要是会的话,可教教大家。

<input type=button value=刷新οnclick="document.execCommand(@#Refresh@#)">

<input type=button value=刷新 οnclick="window.open(@#自身的文件@#,@#_self@#)">

<input type=button value=刷新onClick=document.all.WebBrowser.ExecWB(22,1)>

父页面中存在两个iframe,一个iframe中是一个链接列表,其中的链接指向另一个iframe,用于显示内容。现在当内容内容添加后,在链接列表中添加了一条记录,则需要刷新列表iframe。
在内容iframe的提交js中使用parent.location.reload()将父页面全部刷新,因为另一个iframe没有默认的url,只能通过列表选择,所以只显示了列表iframe的内容。
使用window.parent.frames["列表iframe名字"].location="列表url"即可进刷新列表iframe,而内容iframe在提交后自己的刷新将不受影响。

document.frames("refreshAlarm").location.reload(true);//ok

document.frames("refreshAlarm").document.location.reload(true);//ok

document.frames("refreshAlarm").document.location="/public/alarmsum.asp";//ok

document.getElementByIdx_x("refreshAlarm").src="/public/alarmsum.asp"mce_src="/public/alarmsum.asp"; //ok

document.frames("refreshAlarm").src="/public/alarmsum.asp"mce_src="/public/alarmsum.asp"; //没变化,没动静

注意区别,document.all.refreshAlarm或document.frames("refreshAlarm") 得到的是information.asp页面中那个iframe标签,所以对src属性操作有用。
document.frames("refreshAlarm").document得到iframe里面的内容,也就是"/public/alarmsum.asp"中的内容。

这里需要补充说明的是:

采用document.getElementByIdx_x获取后reload是不可以的

但是可以这样

var myiframe =document.getElementByIdx_x("iframe1");

myiframe.src = myiframe.src; //这样同样可以起到刷新的效果。

自动刷新页面


javascript(js)自动刷新页面的实现方法总结2008-04-18 13:24
自动刷新页面的实现方法总结:
1)
<meta http-equiv="refresh"content="10;url=跳转的页面">
10表示间隔10秒刷新一次
2)
<script language=''javascript''>
window.location.reload(true);
</script>
如果是你要刷新某一个iframe就把window给换成frame的名字或ID号
3)
<script language=''javascript''>
window.navigate("本页面url");
</script>
4>
function abc()
{
window.location.href="/blog/window.location.href";
setTimeout("abc()",10000);
}


刷新本页:
Response.Write("<scriptlanguage=javascript>window.location.href=window.location.href;</script>")

刷新父页:
Response.Write("<script language=javascript>opener.location.href=opener.location.href;</script>")

转到指定页:
Response.Write("<scriptlanguage=javascript>window.location.href='yourpage.aspx';</script>")

刷新页面实现方式总结(HTML,ASP,JS)
'by aloxy

定时刷新:
1,<script>setTimeout("location.href='url'",2000)</script>

说明:url是要刷新的页面URL地址
2000是等待时间=2秒,

2,<meta name="Refresh" content="n;url">

说明:
n is the number of seconds to wait before loading the specified URL.
url is an absolute URL to be loaded.
n,是等待的时间,以秒为单位
url是要刷新的页面URL地址

3,<%response.redirect url%>
说明:一般用一个url参数或者表单传值判断是否发生某个操作,然后利用response.redirect 刷新。

4,刷新框架页
   〈scriptlanguage=javascript>top.leftFrm.location.reload();parent.frmTop.location.reload();</script〉
弹出窗体后再刷新的问题
Response.Write("<script>window.showModalDialog('../OA/SPCL.aspx',window,'dialogHeight:300px; dialogWidth: 427px; dialogTop: 200px; dialogLeft:133px')</script>");//open
            Response.Write("<script>document.location=document.location;</script>");

在子窗体页面代码head中加入<basetarget="_self"/>

刷新的内容加在   if (!IsPostBack) 中

在框架页中右面刷新左面
    //刷新框架页左半部分
    Response.Write("<scriptlanguage=javascript>");
   Response.Write("parent.left.location.href='PayDetailManage_Left.aspx'");
    Response.Write("</script>");

页面定时刷新功能实现

有三种方法:
1,在html中设置:
<title>xxxxx</title>之後加入下面这一行即可!
定时刷新:<METAHTTP-EQUIV="Refresh" content="10">
10代表刷新间隔,单位为秒
2.jsp
<% response.setHeader("refresh","1"); %>
每一秒刷新一次
3.使用javascript:
<script language="javascript">
setTimeout("self.location.reload();",1000);
<script>
一秒一次
页面自动跳转:
1,在html中设置:
<title>xxxxx</title>之後加入下面这一行即可!
定时跳转并刷新:<metahttp-equiv="refresh" content="20;url=http://自己的URL">,
其中20指隔20秒后跳转到http://自己的URL 页面。

点击按钮提交表单后刷新上级窗口

A窗口打开B窗口

然后在B里面提交数据至C窗口

最后要刷新A窗口

并且关闭B窗口

几个javascript函数
//第一个自动关闭窗口

<script language="javascript">
<!--
function clock(){i=i-1
document.title="本窗口将在"+i+"秒后自动关闭!";
if(i>0)setTimeout("clock();",1000);
else self.close();}
var i=2
clock();
//-->
</script>

//第二个刷新父页面的函数

<scriptlanguage="javascript">
opener.location.reload();
</script>
//第三个打开窗口
<scriptlanguage="javascript">
function show(mylink,mytitle,width,height)
{mailwin=window.open(mylink,mytitle,'top=350,left=460,width='+width+',height='+height+',scrollbars=no')}
</script>


getElementByIdx_x js自定义getElementById函数
函数代码: 
复制代码 代码如下:
document.getElementByIdx_x=function(id){ 
if(typeof id =='string') 
return document.getElementById(id); 
else 
throw new error('please pass a string as a id!') 
} 


实例代码: 
复制代码 代码如下:

<div id='box'>9</div> 
<script> 
document.getElementByIdx_x=function(id){ 
if(typeof id =='string') 
return document.getElementById(id); 
else 
throw new error('please pass a string as a id!') 
} 
var timer = window.setInterval(function(){ 
document.getElementByIdx_x('box').innerHTML = parseInt(document.getElementByIdx_x('box').innerHTML) - 1; 
if(parseInt(document.getElementByIdx_x('box').innerHTML) < 0) 
{ 
window.clearInterval(timer); 
window.location = 'http://www.jb51.net'; 
} 
}, 1000); 
</script> 



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值