Javascript inside iFrame

Discussion in 'Javascript' started by Lupus, Mar 5, 2007.

  1. Lupus

    Lupus Guest

    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
     
    Lupus, Mar 5, 2007
    #1
    1. Advertising

  2. Lupus

    Guest

    On Mar 5, 8:21 am, "Lupus" <> 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.
     
    , Mar 5, 2007
    #2
    1. Advertising

  3. Lupus

    crater Guest

    On 5 Mar, 14:21, "Lupus" <> 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>
     
    crater, Mar 5, 2007
    #3
  4. Lupus

    Randy Webb Guest

    crater said the following on 3/5/2007 9:30 AM:
    > On 5 Mar, 14:21, "Lupus" <> 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/
     
    Randy Webb, Mar 5, 2007
    #4
  5. Lupus

    crater Guest

    On 5 Mar, 17:39, Randy Webb <> wrote:
    > crater said the following on 3/5/2007 9:30 AM:
    >
    >
    >
    >
    >
    > > On 5 Mar, 14:21, "Lupus" <> 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!
     
    crater, Mar 6, 2007
    #5
  6. Lupus

    Randy Webb Guest

    crater said the following on 3/6/2007 8:39 AM:
    > On 5 Mar, 17:39, Randy Webb <> 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/
     
    Randy Webb, Mar 6, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daedalous
    Replies:
    3
    Views:
    788
    Daedalous
    Jan 16, 2004
  2. Nathan Carr
    Replies:
    0
    Views:
    286
    Nathan Carr
    Sep 17, 2004
  3. Joe Attardi
    Replies:
    0
    Views:
    540
    Joe Attardi
    Jan 17, 2006
  4. Replies:
    0
    Views:
    132
  5. KDawg44

    Reloading an iFrame inside an iFrame

    KDawg44, Jan 21, 2009, in forum: Javascript
    Replies:
    4
    Views:
    179
    Jorge
    Jan 22, 2009
Loading...

Share This Page