Javascript inside iFrame

L

Lupus

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
 
S

scripts.contact

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.
 
C

crater

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 <script> tags, 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>
 
R

Randy Webb

crater said the following on 3/5/2007 9:30 AM:
You can only access javascript within <script> tags, 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.
 
C

crater

crater said the following on 3/5/2007 9:30 AM:







Who fed you that load of bogus crap?


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

}

document.write is the worst way to try to change a document based on a
condition.

It always works for me!
 
R

Randy Webb

crater said the following on 3/6/2007 8:39 AM:
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.......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top