469,287 Members | 2,436 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

Javascript inside iFrame

Hi everyone,

I've got a problem with javascript. I have a webpage which contains
some javascript functions and an iFrame which contains a second
webpage:

<html>
<head>
....
<script....>
function MyFunction()
{
....
}
</script>
</head>
<body>
<iframe src="calendar/ipopeng.htm" scrolling="no" frameborder="0" >
<LAYER name="gToday:normal:agenda.js" src="calendar/npopeng.htm"
background="webpage.htm"></LAYER>
</iframe>

</body>
</html>

Inside webpage.htm I also have some javascript code. What I need to do
is call the function MyFunction() from inside webpage.htm...
Unfortunetaly (and understandably) it doesn't work just like that:
MyFunction();

How can I do this ?
Kind regards,
Mathew

Mar 5 '07 #1
5 9417
On Mar 5, 8:21 am, "Lupus" <mathieu.m...@gmail.comwrote:
Inside webpage.htm I also have some javascript code. What I need to do
is call the function MyFunction() from inside webpage.htm...
Unfortunetaly (and understandably) it doesn't work just like that:
MyFunction();
Use :
window.top.window.functionName()
or :
top.functionName()

You can access the top window's function properties/methods only when
the frame is from same domain.

Mar 5 '07 #2
On 5 Mar, 14:21, "Lupus" <mathieu.m...@gmail.comwrote:
Hi everyone,

I've got a problem with javascript. I have a webpage which contains
some javascript functions and an iFrame which contains a second
webpage:

<html>
<head>
...
<script....>
function MyFunction()
{
...}

</script>
</head>
<body>
<iframe src="calendar/ipopeng.htm" scrolling="no" frameborder="0" >
<LAYER name="gToday:normal:agenda.js" src="calendar/npopeng.htm"
background="webpage.htm"></LAYER>
</iframe>

</body>
</html>

Inside webpage.htm I also have some javascript code. What I need to do
is call the function MyFunction() from inside webpage.htm...
Unfortunetaly (and understandably) it doesn't work just like that:
MyFunction();

How can I do this ?

Kind regards,
Mathew
You can only access javascript within <scripttags, so to call your
MyFunction() function you have to call thus: <script>myFunction()</
script>.

If you need to access a return value and do something different on you
web page accordingly, use dynamic HTML...

<script>
var retval = MyFunction()
if (retval == condition) {
document.write(some HTML)
...
}
</script>

Mar 5 '07 #3
crater said the following on 3/5/2007 9:30 AM:
On 5 Mar, 14:21, "Lupus" <mathieu.m...@gmail.comwrote:
>Hi everyone,

I've got a problem with javascript. I have a webpage which contains
some javascript functions and an iFrame which contains a second
webpage:

<html>
<head>
...
<script....>
function MyFunction()
{
...}

</script>
</head>
<body>
<iframe src="calendar/ipopeng.htm" scrolling="no" frameborder="0" >
<LAYER name="gToday:normal:agenda.js" src="calendar/npopeng.htm"
background="webpage.htm"></LAYER>
</iframe>

</body>
</html>

Inside webpage.htm I also have some javascript code. What I need to do
is call the function MyFunction() from inside webpage.htm...
Unfortunetaly (and understandably) it doesn't work just like that:
MyFunction();

How can I do this ?

Kind regards,
Mathew

You can only access javascript within <scripttags, so to call your
MyFunction() function you have to call thus: <script>myFunction()</
script>.
Who fed you that load of bogus crap?
If you need to access a return value and do something different on you
web page accordingly, use dynamic HTML...
function getTheReturnValue(){
theReturnValue = window.top.parent.myFunction();
}
<script>
var retval = MyFunction()
if (retval == condition) {
document.write(some HTML)
document.write is the worst way to try to change a document based on a
condition.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 5 '07 #4
On 5 Mar, 17:39, Randy Webb <HikksNotAtH...@aol.comwrote:
crater said the following on 3/5/2007 9:30 AM:


On 5 Mar, 14:21, "Lupus" <mathieu.m...@gmail.comwrote:
Hi everyone,
I've got a problem with javascript. I have a webpage which contains
some javascript functions and an iFrame which contains a second
webpage:
<html>
<head>
...
<script....>
function MyFunction()
{
...}
</script>
</head>
<body>
<iframe src="calendar/ipopeng.htm" scrolling="no" frameborder="0" >
<LAYER name="gToday:normal:agenda.js" src="calendar/npopeng.htm"
background="webpage.htm"></LAYER>
</iframe>
</body>
</html>
Inside webpage.htm I also have some javascript code. What I need to do
is call the function MyFunction() from inside webpage.htm...
Unfortunetaly (and understandably) it doesn't work just like that:
MyFunction();
How can I do this ?
Kind regards,
Mathew
You can only access javascript within <scripttags, so to call your
MyFunction() function you have to call thus: <script>myFunction()</
script>.

Who fed you that load of bogus crap?
If you need to access a return value and do something different on you
web page accordingly, use dynamic HTML...

function getTheReturnValue(){
theReturnValue = window.top.parent.myFunction();

}
<script>
var retval = MyFunction()
if (retval == condition) {
document.write(some HTML)

document.write is the worst way to try to change a document based on a
condition.
It always works for me!

Mar 6 '07 #5
crater said the following on 3/6/2007 8:39 AM:
On 5 Mar, 17:39, Randy Webb <HikksNotAtH...@aol.comwrote:
>crater said the following on 3/5/2007 9:30 AM:
<snip>
>><script>
var retval = MyFunction()
if (retval == condition) {
document.write(some HTML)
document.write is the worst way to try to change a document based on a
condition.

It always works for me!
I didn't say it wouldn't. But I bet "eval always works" for you too?

P.S. Try this code:

<script type="text/javascript">
window.onload = itWontDoWhatYouThink;

function itWontDoWhatYouThink(){
document.write('Some Content');
}
</script>

And then view the source of the page.......
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 6 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Magnus | last post: by
8 posts views Thread by chrisdude911 | last post: by
6 posts views Thread by den 2005 | last post: by
2 posts views Thread by Adriano | last post: by
16 posts views Thread by Phlip | last post: by
2 posts views Thread by sorobor | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.