473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Get opener element from a child

Hi

How do I get the contents of an element in the opener and show them in the
child?
What I'm trying to do is something like this:

In the opener: <h1 id="pgtitle">Office XP</h1>

In the child:
function gt_pageCont () {
var pagetitle = window.opener.document.getElementById("pgtitle");
var pagetext = "<h1>\""+title+"\"</h1><p>Here are some more info about \""
+title+ "\".</p>";
document.write(pagetext);
}

and:
<body onload="gt_pageCont();">

I know that something is missing in the function, because I've tested it and
the child displays [Object] instead of "Office XP". Can someone help me
please?

Thanks.

--
Please, remove the TRAP to contact me
--
Jul 23 '05 #1
5 4745
geotso wrote:
function gt_pageCont () {
var pagetitle = window.opener.document.getElementById("pgtitle");
var pagetext = "<h1>\""+title+"\"</h1><p>Here are some more info about \""
+title+ "\".</p>";
document.write(pagetext);
}


var pagetitle = opener.document.getElementById("pgtitle").innerHTM L;
var pagetext = "<h1>\""+pagetitle+"\"<\/h1><p>Here are some more info
about \""
+pagetitle+ "\".<\/p>";
document.write(pagetext);
}

Instead of using document.write() you may also set an element's
innerHTML property accordingly.

Daniel
Jul 23 '05 #2
Daniel Kirsch wrote:
[...]
var pagetitle = opener.document.getElementById("pgtitle").innerHTM L;


You could also use:

opener.document.getElementById('pgtitle').firstChi ld.data;

But both methods have the restriction that if there is anything in the
pgtitle element other than plain text, you will not get what you want.

e.g. if you add extra markup inside the element, the innerHTML method
will return the extra markup along with the text and the firstChild
method will do different things depending on where the markup is.

e.g.
<h1 id="pgtitle">Office <span
style="font-weight: normal;">XP</span></h1>

will return "Office "

<h1 id="pgtitle"><span
style="font-weight: normal;">Office XP</span></h1>

will return "undefined".

Which highlights that using the document content as a source of data is
not always reliable, particularly when HTML munges markup and content
so thoroughly. Maybe you should consider putting the pgtitle value
somewhere else where it will not be affected by markup - say a global
variable for the opener page or a meta tag? That should mean you don't
need to parse whatever is returned to ensure it is what you want.

If you stick with the innerHTML method, you probably should use a
regular expression to remove any markup between tag delimiters.

Or have I been rambling for no particular purpose...

--
Rob
Jul 23 '05 #3
RobG wrote:
But both methods have the restriction that if there is anything in the
pgtitle element other than plain text, you will not get what you want.


innerHTML returns the original HTML. If you just want to get the text
content without markup, one might use innerText (IE) or textContent
(newer Geckos) or of course a regExp on the innerHTML value.

Daniel
Jul 23 '05 #4
Daniel Kirsch wrote:
RobG wrote:
But both methods have the restriction that if there is anything in the
pgtitle element other than plain text, you will not get what you want.

innerHTML returns the original HTML.


No, it returns the normalized HTML as generated by the browser.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5
Randy Webb wrote:
No, it returns the normalized HTML as generated by the browser.


Of course.
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David Norman | last post by:
How can I create an xml schema where both of the following documents are valid? <theElement> <child>some text</child> </theElement> and <theElement>1234</theElement>
2
by: Bostonasian | last post by:
I am trying to append options to dropdown in parent window from option items in child window. In parent window, I have following code: <script language="javascript"> function...
6
by: Donius | last post by:
Is there a simple and clean way to get the window object that contains an element that is passed into a function? I want to throw some alerts / confirms, but don't want to switch away from...
2
by: gialby | last post by:
Ciao i have this problem.... i have a main asp page with this code PARENT PAGE <script language="vbScript"> function ricerca() ...
1
by: adamredwards | last post by:
I have a page with some form elements that are dynamically generated. They are inserted into the dom by first cloning a node, changing the values like name, and then inserted with insertBefore(). ...
4
by: patrizio.trinchini | last post by:
Hi all, I'm new to XSLT and maybe my problem have a very trivial answer, but I need an expert that point me in the right direction. What I would obtain is to remove all the elements that have a...
14
by: marfi95 | last post by:
I'm trying to iterate through a list of child nodes. It seems like to get the text value of the node, you have to do a node->getFirstChild()->getNodeValue. This being said, there is a...
4
by: MA | last post by:
Hi, How to access the total number of child nodes from a parent node. For example, I would like to get the total number of child nodes from <parent1and <parent2node. The SelectNodes method...
2
by: newlearner | last post by:
Hi all, on clicking the child node or element I need to get the id of the root element or node. id it possible, I have no idea for example <table> <tr><td id="root"> <table> <tr><td>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.