window.location.target控制问题

location对象没有target属性.
用js遍历所有的a,设置它们的target值为p.
或者在文档单击的时候.判读点的是不是连接.然后改变连接的target值..
下面是实现代码.

<!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>
<title> new document </title>
</head>
<body>
<iframe id="a1" name="a1" src="about:blank" width="450" height="350"></iframe>
<iframe id="a2" name="a2" src="about:blank" width="450" height="350"></iframe><hr>
   <a href="http://www.baidu.com" target="a1">百度</a><br>
   <a href="http://g.cn" target="a1">Google</a>
   <input type="button" value="改变连接为在第二个IFRAME" οnclick="document.onclick = c;target='a2';" />
   <input type="button" value="改变连接为在第一个IFRAME" οnclick="document.onclick = c;target='a1';" />
   <script type="text/javascript">
   //<![CDATA[
       var target = 'a1';
       function c(e){
           e = e || window.event;
           var o = e.srcElement||e.target;
           if(o.tagName.toLowerCase() == 'a'){
               o.target = target;
           };
       }
   //]]>
   </script>
</body>
</html>

另一个例子 
这是框架页,另外两个页面代码省了,但加javascrpt示例
  1. <frameset rows="*"  cols="241,*" framespacing="0" frameborder="NO" border="0">  
  2.         <frame src="UntitledFrame2.htm" id="leftFrame" name="leftFrame" scrolling="NO" noresize>  
  3.         <frame src="Untitled-1.htm" id="rigthmain" name="rigthmain">  
  4. </frameset> 

在 UntitledFrame2.htm面中加入下面内空
  1. <script>  
  2. function aa(){  
  3. window.parent.rigthmain.location.href="http://www.baidu.com";  

<a onClick=" aa()">a</a> 

这也是一个很好用的跳转

另外几种调转的例子,其实基本上就是要对页面之间的关系弄清楚,自己有本javascrip书上写的很详细
自己要认真看

如果你要让最顶层的框架跳转,就是整个页面
window.top.location="……"

如果你要让当前页面的父框架跳转
window.parent.location="……"

如果你要让指定框架跳转
window.top.框架名.location="……";

到父后在定位
window.parent.框架名.location="";

下面这段代码很经典,解决的是这样的一个问题
我用母版页来分隔页面,但又用到iframe,此时问题出现了,一旦页面超时退到登录页面,这个页面老是了现在iframe里,而不是覆盖整个页。然后在登录页中加入下面的这段代码就可以搞定
<script language="javascript" type="text/javascript">
if ( parent.location != document.location )
{// 我的理解document.location指登录页的url,parent.location是母版页的url,当不同时,就覆掉它
   parent.location = document.location;
}  
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值