对象只能添加到创建它的页面上,不可以跨页面

 假如有3个页面

 main.html(主要负责iframe中间页面) 包含 iframe.html(主要负责出数据,跳转到真实内容页面)

 内容页面为 content.html(真实内容)

  这几个页面加在一起,主要实现导航功能.

  中间注意DOM 对象的跨页面问题!!!!!

main.html

<html>
    
<head>
        
<title>Main</title>
    
</head>
    
<body>
        
<div id="navigator"><label>Navigator Bar : </label><a href="main.html">Home</a><label> &gt; </label></div>
        
<iframe src="iframe.html" name="content" width="90%" height="90%"></iframe>
    
</body>
</html>
iframe.html
<html>
    
<head>
        
<title>iframe</title>
        
<script type="text/javascript">
            
function navigator(anchor){
                
//navigator div element in parent page
                var navigatorBar = window.parent.document.getElementById("navigator");
                
                
//attention!!!
                //when create an object,you can only use it in the page where create the object,cann't cross pages
                var newAnchor = window.parent.document.createElement("a");
                newAnchor.href 
= anchor.href;
                newAnchor.target 
= "content";
                newAnchor.appendChild(window.parent.document.createTextNode(anchor.firstChild.nodeValue));

                
//append anchor to parent page
                navigatorBar.appendChild(newAnchor);
            }

        
</script>
    
</head>
    
<body>
        
<a href="content.html"onclick="navigator(this)">Add this anchor to parent page</a>
    
</body>
</html>
content.html
<html>
    
<head>
        
<title>Content</title>
    
</head>
    
<body>
        
<p>Content Page</p>
    
</body>
</html>
上一篇: XMLHttpRequest and jsp servlet
下一篇: Study Flex
ufologist
博客等级 码龄20年 2粉丝 9原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值