473,480 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Javascript to access main document from within iframe question

First off, I'm new here.

I have a question about accessing an element in Javascript. Here's a
simple example:

</html></body>
<div id="div1"... </div>

<iframe... src="./javascript_in_here.html" ...></iframe>

<div id="div2"... </div>
</body></html>
In the iframe linked page is a Javascript procedure. I cannot seem to get
to the objects (such as div1 and div2) on the main document. Everything I
try seems to return a NULL or error.

Any assistance greatly appreciated.

--
VAXman- A Bored Certified VMS Kernel Mode Hacker VAXman(at)TMESIS(dot)COM

"Well my son, life is like a beanstalk, isn't it?"
Jun 16 '07 #1
6 8890
Ty this:
<html><body><!-- a.htm -->
<div id="div1">1</div>
<iframe src="./b.htm" ></iframe>
<div id="div2">2</div>
</body></html>

<html><head><!-- b.htm -->
<script type="text/javascript">
function f(){
alert(top.document.getElementById('div1').innerHTM L+'
'+top.document.getElementById('div2').innerHTML);
}
</script></head><body onload="f()"></body></html>

Jun 17 '07 #2
Try this:
<html><body><!-- a.htm -->
<div id="div1">1</div>
<iframe src="./b.htm" ></iframe>
<div id="div2">2</div>
</body></html>

<html><head><!-- b.htm -->
<script type="text/javascript">
function f(){
alert(top.document.getElementById('div1').innerHTM L+'
'+top.document.getElementById('div2').innerHTML);
}
</script></head><body onload="f()"></body></html>

Jun 17 '07 #3
Try this:
<html><body><!-- a.htm -->
<div id="div1">1</div>
<iframe src="./b.htm" ></iframe>
<div id="div2">2</div>
</body></html>

<html><head><!-- b.htm -->
<script type="text/javascript">
function f(){
alert(
top.document.getElementById('div1').innerHTML
+' '
+top.document.getElementById('div2').innerHTML);
}

Jun 17 '07 #4
Try this:
<html><body><!-- a.htm -->
<div id="div1">1</div>
<iframe src="./b.htm" ></iframe>
<div id="div2">2</div>
</body></html>
<html><head><!-- b.htm -->
<script type="text/javascript">
function f(){
alert(
top.document.getElementById('div1').innerHTML
+' '
+top.document.getElementById('div2').innerHTML);
}

Jun 17 '07 #5
Try this:
<html><body><!-- a.htm -->
<div id="div1">1</div>
<iframe src="./b.htm" ></iframe>
<div id="div2">2</div>
</body></html>
<html><head><!-- b.htm -->
<script type="text/javascript">
function f(){
alert(
top.document.getElementById('div1').innerHTML
+' '
+top.document.getElementById('div2').innerHTML);}

Jun 17 '07 #6
<html><body><!-- a.htm -->
<div id="div1">1</div>
<iframe src="./b.htm" ></iframe>
<div id="div2">2</div>
</body></html>
<html><head><!-- b.htm -->
<script type="text/javascript">
function f(){
alert(top.document.getElementById('div1').innerHTM L
+' '+top.document.getElementById('div2').innerHTML);
}
</script></head><body onload="f()"></body></html>

Jun 17 '07 #7

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

Similar topics

0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7076
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
6873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5321
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,...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.