Fork me on GitHub

父页面刷新 保持iframe页面url不变

  思路:点击父页面时写cookies--》刷新时从cookies中奖内容读取出来。

  本文转自:http://blog.163.com/sdolove@126/blog/static/114637885201282415580/

<body onbeforeunload="check()">
 <iframe id='fjob' name='fjob' style='width:757px;margin-top:10px; height:960px;padding:0px 5px;border:0 solid #f00;' frameborder="0" scrolling="no" 
 src={if $redirect_url}
 {$redirect_url}
 {else}"http://******.cn/jobs"{/if} >
 </iframe>
</body>

<script>
$(document).ready(function()
{
 var url = getCookie('pre_url');
 if (url)
 {
  $("#fjob").attr('src', );
 }
});

function check()
{
 pre_url = window.frames['fjob'].document.location;
 setCookie('pre_url', pre_url, 1);
}

function getCookie(c_name)
{
 if (document.cookie.length>0)
   {
   c_start=document.cookie.indexOf(c_name + "=")
   if (c_start!=-1)
  { 
  c_start=c_start + c_name.length+1 
  c_end=document.cookie.indexOf(";",c_start)
  if (c_end==-1) c_end=document.cookie.length
  return unescape(document.cookie.substring(c_start,c_end))
  } 
   }
 return ""
}

function setCookie(c_name,value,expiredays)
{
 var exdate=new Date()
 exdate.setDate(exdate.getDate()+expiredays)
 document.cookie=c_name+ "=" +escape(value)+
 ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
</script>

 

posted @ 2016-01-31 20:49  秋楓  阅读(4007)  评论(0编辑  收藏  举报