window.opener.document

简介:
travisbrown (TechnicalUser)
10 May 07 1:07
I'm trying to set the value/innerHTML of a text area in a parent page from a  popup. Is there anything obviously wrong with the script below? The first two elements are passing back properly. job_desc is not working with either innerHTML or value. I've double-checked that the id names are correct, and I'm not getting any errors in the FF error console.

CODE

<script type="text/javascript">
function transferTemplate(id) {
    window.opener.document.getElementById('job_mini_desc').value = document.getElementById('job_mini_desc_' + id).value;
    window.opener.document.getElementById('job_title').value = document.getElementById('job_title_' + id).value;
    window.opener.document.getElementById('job_desc').value = document.getElementById('job_desc_' + id).value;
    //window.opener.document.getElementById('job_desc').innerHTML = document.getElementById('job_desc_' + id).value
    //self.close();
}
</script>

The target element is 

CODE

<textarea name="job_desc" id="job_desc">
  </textarea>
Tek-Tips Forums is Member Supported. Click Here to donate.
monksnake (Programmer)
10 May 07 9:28
Where is this element defined in your  HTML?:

CODE

document.getElementById('job_desc_' + id).value


Can you post that element along with the call to the function transferTemplate?

I don't see anything immediately wrong, but I also don't see all the factors involved.

monkeysnake <.

travisbrown (TechnicalUser)
10 May 07 10:18
Here's the popup html

CODE


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Employment Templates</title>
<script type="text/javascript">
function transferTemplate(id) {
    window.opener.document.getElementById('job_mini_desc').value = document.getElementById('job_mini_desc_' + id).value;
    window.opener.document.getElementById('job_title').value = document.getElementById('job_title_' + id).value;
    window.opener.document.getElementById('job_desc').value = document.getElementById('job_desc_' + id).value;
    //window.opener.document.getElementById('job_desc').innerHTML = document.getElementById('job_desc_' + id).value
    //self.close();
}
</script>
<script type="text/javascript" src="../_scripts/common.js"></script>
<link href="admin.css" rel="stylesheet" type="text/css" media="screen">
</head>

<body>
<ul>

    <li id="job_36"><a href="javascript:transferTemplate(36);" id="" >ASSISTANT DISPATCHER W/CLASS 1</a>
    <input id="job_title_36" type="hidden" value="ASSISTANT DISPATCHER W/CLASS 1" />
    <input id="job_mini_desc_36" type="hidden" value="Required in our Edmonton Branch" />
    <input id="job_desc_36" type="hidden" value="test 123" />
    <a href="javascript:sndReq('process_job_template.asp?job_template_id=36&mode=delete','job_36');">delete</a>
    </li>

    <li id="job_37"><a href="javascript:transferTemplate(37);" id="" >HOUSEHOLD GOODS RECEIVER</a>
    <input id="job_title_37" type="hidden" value="HOUSEHOLD GOODS RECEIVER" />
    <input id="job_mini_desc_37" type="hidden" value="Required in our Edmonton Freight Division" />
    <input id="job_desc_37" type="hidden" value="&lt;p&gt;We are currently seeking a summer& amp;nbsp;household goods receiver&amp;nbsp;in our freight&amp;nbsp;division to commence June 1st, 2007.&amp;nbsp; This position will end in August / September.&lt;/p&gt;&lt;h2&gt;Skills and duty requirements include:&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;Professionalism in customer service &lt;/li&gt;&lt;li&gt;Excellent organization and planning abilities&lt;/li&gt;&lt;li&gt;Working with a partner to use dollies and straps to move very heavy items&lt;/li&gt;&lt;li&gt;Breaking down of packing material, folding pads, and other general warehouse duties including..." />
    <a href="javascript:sndReq('process_job_template.asp?job_template_id=37&mode=delete','job_37');">delete</a>
    </li>

</ul>
</body>
</html>
monksnake (Programmer)
10 May 07 10:52
I just set up a sample that uses your  popup window and it worked perfectly.

Here is what I got for your function (untouched, just removed comments):

CODE

function transferTemplate(id) {
    window.opener.document.getElementById('job_mini_desc').value = document.getElementById('job_mini_desc_' + id).value;
    window.opener.document.getElementById('job_title').value = document.getElementById('job_title_' + id).value;
    window.opener.document.getElementById('job_desc').value = document.getElementById('job_desc_' + id).value;
    self.close();
}

Here is my test HTML file that calls the popup:

CODE

<?xml version="1.0" encoding="iso-8859-1"?><!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>
</head>
<body>
   <span id="job_mini_desc"</span>
   <span id="job_title"></span>
   <textarea id="job_desc"></textarea>
   <input type="button" onclick="window.open('test.html', 'popup', 'height=200, width=300')" value="CLICK" /> 
</body>
</html>

The only thing I can think of why your code doesn't work is you may have more than one id = "job_desc"

 

本文转自kenty博客园博客,原文链接http://www.cnblogs.com/kentyshang/archive/2007/05/29/764011.html如需转载请自行联系原作者

kenty
相关文章
笔记14-常用API&异常
笔记14-常用API&异常
笔记14-常用API&异常
|
Web App开发 前端开发
|
Java 关系型数据库 数据库
Unitils集成DBUnit的问题-解决方案
  Unitils在集成DBunit时,如果数据库是mysql时,就会出现一些如下:   org.unitils.core.UnitilsException: Error inserting test data from DbUnit dataset for method.
941 0
|
8天前
|
人工智能 自然语言处理 API
深入浅出LangChain与智能Agent:构建下一代AI助手
LangChain为大型语言模型提供了一种全新的搭建和集成方式,通过这个强大的框架,我们可以将复杂的技术任务简化,让创意和创新更加易于实现。本文从LangChain是什么到LangChain的实际案例到智能体的快速发展做了全面的讲解。
279541 52
深入浅出LangChain与智能Agent:构建下一代AI助手
|
9天前
|
设计模式 人工智能 JSON
一文掌握大模型提示词技巧:从战略到战术
本文将用通俗易懂的语言,带你从战略(宏观)和战术(微观)两个层次掌握大模型提示词的常见技巧,真正做到理论和实践相结合,占领 AI 运用的先机。
237784 4
|
9天前
|
NoSQL Cloud Native Redis
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新
阿里云瑶池数据库团队后续将持续参与Valkey社区,如过往在Redis社区一样耕耘,为开源社区作出持续贡献。
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新
|
9天前
|
关系型数据库 分布式数据库 数据库
PolarDB闪电助攻,《香肠派对》百亿好友关系实现毫秒级查询
PolarDB分布式版助力《香肠派对》实现百亿好友关系20万QPS的毫秒级查询。
PolarDB闪电助攻,《香肠派对》百亿好友关系实现毫秒级查询
|
3天前
|
机器人 Linux API
基于Ollama+AnythingLLM轻松打造本地大模型知识库
Ollama是开源工具,简化了在本地运行大型语言模型(ile优化模型运行,支持GPU使用和热加载。它轻量、易用,可在Mac和Linux上通过Docker快速部署。AnythingLLM是Mintplex Labs的文档聊天机器人,支持多用户、多种文档格式,提供对话和查询模式,内置向量数据库,可高效管理大模型和文档。它也是开源的,能与Ollama结合使用,提供安全、低成本的LLM体验。这两款工具旨在促进本地高效利用和管理LLMs。
78213 19
|
10天前
|
消息中间件 Cloud Native Serverless
RocketMQ 事件驱动:云时代的事件驱动有啥不同?
本文深入探讨了云时代 EDA 的新内涵及它在云时代再次流行的主要驱动力,包括技术驱动力和商业驱动力,随后重点介绍了 RocketMQ 5.0 推出的子产品 EventBridge,并通过几个云时代事件驱动的典型案例,进一步叙述了云时代事件驱动的常见场景和最佳实践。
246779 2
|
7天前
|
物联网 PyTorch 测试技术
手把手教你捏一个自己的Agent
Modelscope AgentFabric是一个基于ModelScope-Agent的交互式智能体应用,用于方便地创建针对各种现实应用量身定制智能体,目前已经在生产级别落地。