对象只能添加到创建它的页面上,不可以跨页面
来源:互联网 发布:中国历年财政支出数据 编辑:程序博客网 时间:2024/06/06 07:12
假如有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> > </label></div>
<iframe src="iframe.html" name="content" width="90%" height="90%"></iframe>
</body>
</html>
<head>
<title>Main</title>
</head>
<body>
<div id="navigator"><label>Navigator Bar : </label><a href="main.html">Home</a><label> > </label></div>
<iframe src="iframe.html" name="content" width="90%" height="90%"></iframe>
</body>
</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>
<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>
<html>
<head>
<title>Content</title>
</head>
<body>
<p>Content Page</p>
</body>
</html>
<head>
<title>Content</title>
</head>
<body>
<p>Content Page</p>
</body>
</html>
- 对象只能添加到创建它的页面上,不可以跨页面
- JS将复制的页面内容以纯文本的形式粘贴到自己的页面上
- 将播放器以字符串的形式输出到页面上,并实现播放功能
- 页面中iframe中嵌入一个跨域的页面,让这个页面按照嵌入的页面宽高大小显示的方式;iframe嵌套的页面不可以编辑的问题解决方案
- 获取页面上TextBox并改变它的值
- 页面常用到的js--待添加
- Ajax 页面对象创建
- iOS开发,TableViewCell上添加Xib创建的View会出现页面混乱
- 控件创建后,先设置属性,再添加到页面,导致工作不正常的问题
- C++只能在堆上或只能在栈上创建累的对象
- 获取父页面的数据,并且hidden到页面上
- 跳转到上一次浏览的页面
- 页面不可添加中文、不可粘贴、小数和负数控制
- (插件收藏)Progress.js – 为页面上的任意对象创建进度条效果
- Action从页面获取值只能获取到对象第一个表单值
- Java中返回的对象无法再jsp页面中循环遍历到标签上
- 以流的方式在html页面上显示图片
- 页面上显示图片 以流的方式获取
- happiness feeling
- 实践测试驱动开发
- 如何使用ASP获取远程的计算机名
- AOP 解释
- SPI简介
- 对象只能添加到创建它的页面上,不可以跨页面
- 利用CreateToolhelp32Snapshot改内存
- 进程的一些概念和动作(未全待续)
- 倾力打造:主流服务器操作系统“大排挡”
- [ZZ] JavaScript中event的x,clientX,offsetX的区别
- 重要莫过于流程,重要莫过于制度,重要莫过于团队
- 友益文书软件加密深度分析
- 充值卡意外窜红 成今年春节网购销售冠军
- 2007春节网购销售排行