`
nvry
  • 浏览: 316614 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

window.location.target控制问题

    博客分类:
  • view
阅读更多

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" onclick="document.onclick = c;target='a2';" />
   <input type="button" value="改变连接为在第一个IFRAME" onclick="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>
分享到:
评论

相关推荐

    JavaScript权威指南

    The Location Object Section 13.10. The History Object Section 13.11. Multiple Windows and Frames Chapter 14. The Document Object Section 14.1. Document Overview Section 14.2. Dynamically ...

    ie与session丢失(新窗口cookie丢失)实测及解决方案

    今天在一个群中有人问到ie6中使用js的open,发现新窗口中并获取不到session, 经过使用下面的测试代码测试发现,是因为phpsessionid储存是进程级的有效期,只有同一进程才能获取得到,很多人说,open后或是target=”_blank...

    javascript小技巧

    window.onresize=new Function("window.location.reload()") } function setmessage2(){ topmsg=new Layer(window.innerWidth) topmsg.bgColor=backgroundcolor regenerate2() topmsg.document.write(message) ...

    js打开新窗口方法整理

    window.top.location=url 可以在iframe中的页面在父窗口刷新打开 window.open方法可控制的样式丰富,比如我们可以控制窗口显示的大小,窗口显示的内容,以及位置等等。都是使用js中的window.open有一个缺点就是容易...

    Debugging with GDB --2007年

    Table of Contents Summary of GDB . . . . . . . . ....Free software ....Contributors to GDB ....A Sample GDB Session ....Loading the Executable ....Setting Display width....Setting Breakpoints ....Running the executable ...

    一个简单的网页框架 frame

    window.open('index.html','','toolbar=no,menubar=no,location=no,status=no,width=' + screen.width + ',height=' + screen.height + ',left=0,top=0'); } &lt;meta name= "robots " content= "noindex "&gt; ...

    js 有框架页面跳转(target)三种情况下的应用

    jsp: 代码如下: [removed] window.parent.frames.location.href=”../welcome.en” [removed] java: 代码如下: PrintWriter out = response.getWriter(); out.write(“[removed]window.parent.frames.location.href...

    js使用小技巧

    查看网页源代码 onclick="window.location = "view-source:"+ "http://www.csdn.net/""&gt; 关闭输入法 自动全选 &lt;input type=text name=text1 value="123" onfocus="this.select()"&gt; ENTER键可以让光标移到下...

    Optimization Modelling A Practical Approach

    List of Figures...................................................................................................... xv List of Tables ...................................................................

    ASP.NET程序中常用的三十三种代码.txt

    &lt;asp:HyperLinkColumn Target="_blank" headertext="ID号" DataTextField="id" NavigateUrl="aaa.aspx?id=’  &lt; %# DataBinder.Eval(Container.DataItem, "数据字段1")%&gt;’ & name=’&lt;% # DataBinder.Eval...

    浮点vfdsfJAVA实现链表,双向链表.txtJAVA实现链表,双向链表.txt

    &lt;li&gt;&lt;input id="cb_agree" name="cb_agree" type="checkbox" value="" /&gt;同意&lt;a href="http://download.csdn.net/help" target="_blank"&gt;CSDN资源上传协议&lt;/a&gt;&lt;/label&gt; 验证码: ...

    js+html滑出式菜单

    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } var NS IE=document.all; NS=document.layers; hdrFontFamily="Verdana"; ...

    ASP.NET常用代码

    &lt;asp:HyperLinkColumn Target="_blank" headertext="ID号" DataTextField="id" NavigateUrl="aaa.aspx?id='&lt;%# DataBinder.Eval(Container.DataItem, "数据字段1")%&gt;' & name='&lt;%# DataBinder.Eval(Container.Data...

    原创-javascript服务器交互型可编辑表格和我的js常用库

    name : 'quality_target', editorType : 'select', dataUrl : 'WaterQualityAction?method=AjaxSelect¶=LEVEL', defaultValue : '请选择' }, { name : 'area_qualityTarget', editor...

    C8051F320_USB_Bulk

    b) Open the Connection Options window by selecting Options-&gt; Connection Options... in the IDE menus. In the Debug Interface section, select C2. c) Connect to the target C8051F32x device ...

    wayos认证页面

    alert(msg.msg)}}function get_ld(){var tmp=window.location.href.split("ld=");if(tmp.length==2){return tmp[1]}return""}var ld="";var init=0;$(function(){ld=get_ld();var get_val=getCookie("save");if(get_...

    编辑任意PDF文件

    Navigating through bookmarks is an efficient way for users to link to the target location quickly. To jump to a topic that you are interested, you can just simply click the bookmark. 4.Viewing ...

    登录页面源码

    -- Brand and toggle get grouped for better mobile display --&gt;&lt;div class="navbar-header"&gt;&lt;button type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" class="navbar-toggle"&gt;...

    三星9305收索

    &lt;!...--STATUS OK--&gt;&lt;html&gt;&lt;head&gt;;..._position:;min-height:100%}#head{padding-bottom:100px;text-align:center;*z-index:1}#ftCon{height:100px;position:absolute;bottom:44px;text-align:center;...

    圣诞节 祝福网站 全部源码

    window.location.replace(url); return false; } --&gt; &lt;!--SCRIPT language=JavaScript src="snow.js"&gt; &lt;BGSOUND loop=infinite src="jinbells.mid" tppabs="jinbells.mid"&gt; ; margin:0 auto; height:auto"&gt; ...

Global site tag (gtag.js) - Google Analytics