Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Javascript inside iFrame

Reply
Thread Tools

Javascript inside iFrame

 
 
Lupus
Guest
Posts: n/a
 
      03-05-2007
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

 
Reply With Quote
 
 
 
 
scripts.contact@gmail.com
Guest
Posts: n/a
 
      03-05-2007
On Mar 5, 8:21 am, "Lupus" <(E-Mail Removed)> wrote:
> 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.



 
Reply With Quote
 
 
 
 
crater
Guest
Posts: n/a
 
      03-05-2007
On 5 Mar, 14:21, "Lupus" <(E-Mail Removed)> wrote:
> 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>

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      03-05-2007
crater said the following on 3/5/2007 9:30 AM:
> On 5 Mar, 14:21, "Lupus" <(E-Mail Removed)> wrote:
>> 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>.


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/
 
Reply With Quote
 
crater
Guest
Posts: n/a
 
      03-06-2007
On 5 Mar, 17:39, Randy Webb <(E-Mail Removed)> wrote:
> crater said the following on 3/5/2007 9:30 AM:
>
>
>
>
>
> > On 5 Mar, 14:21, "Lupus" <(E-Mail Removed)> wrote:
> >> 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>.

>
> 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!

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      03-06-2007
crater said the following on 3/6/2007 8:39 AM:
> On 5 Mar, 17:39, Randy Webb <(E-Mail Removed)> wrote:
>> 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reloading an iFrame inside an iFrame KDawg44 Javascript 4 01-22-2009 10:52 AM
problems with iframe inside another iframe (with designMode="on") sammyleong@gmail.com Javascript 0 01-19-2006 12:28 AM
Div inside an iframe - how to set height relative to the iframe's visible size? Joe Attardi Javascript 0 01-17-2006 08:01 PM
Need to get offsetLeft of an iframe or div inside another iframe Nathan Carr Javascript 0 09-17-2004 01:27 PM
Get form values from iframe (1) to iframe (2) inside a layer in iframe (1) Daedalous Javascript 3 01-16-2004 11:08 AM



Advertisments