iframe and attachevent

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • foldface@yahoo.co.uk

    #1

    iframe and attachevent

    Hi
    Completely ignore the non-standard nature of the noddy example
    below.
    I want to capture a mouse click in a frame from outside that frame.
    Everything
    I read online seems to indicate its something like the below but I
    just can't get it to work. any ideas?
    Ta
    F

    <script>
    function Temp()
    {
    alert('hi')
    }

    function SetUp()
    {
    var myIFrame2 = document.getEle mentById("frame 2");

    myIFrame2.attac hEvent('onclick ', Temp);
    }
    </script>

    <body onload=SetUp()>
    <form>
    <IFRAME id=frame2 src="http://www.google.co.u k" width=100%
    height="700" scrolling="auto ">
    [Your user agent does not support frames or is
    currently configured
    not to display frames. However, you may visit
    <A href="temp2.htm l">the related document.</A>]
    </IFRAME>
    </form>
    </body>
  • Richard Cornford

    #2
    Re: iframe and attachevent

    foldface@yahoo. co.uk wrote:[color=blue]
    > Completely ignore the non-standard nature of the
    > noddy example below.[/color]

    So long as the example actually relates to the problem.
    [color=blue]
    > I want to capture a mouse click in a frame from
    > outside that frame.[/color]

    For which you would have to attach an event listener to the document
    object within the IFRAME.
    [color=blue]
    > Everything I read online seems to indicate its something
    > like the below but I just can't get it to work. any ideas?[/color]

    Find alternative reading matter.
    [color=blue]
    > <script>
    > function Temp()
    > {
    > alert('hi')
    > }
    >
    > function SetUp()
    > {
    > var myIFrame2 = document.getEle mentById("frame 2");
    >
    > myIFrame2.attac hEvent('onclick ', Temp);[/color]

    There is a distinction between the IFRAME element in the containing
    document and the frame object that contains the IFRAME's content. You
    are attaching your listener to the IFRAME element. If it had borders you
    probably could pick up clicks on those borders, but interaction with the
    contents should not be expected to propagate to the containing document
    in any way.
    [color=blue]
    > }
    > </script>
    >
    > <body onload=SetUp()>
    > <form>
    > <IFRAME id=frame2 src="http://www.google.co.u k" width=100%[/color]
    <snip> ^^^^^^^^^^^^^^^ ^^^^^^^^

    Unless you are working for google uk this is exactly the type of
    situation that cross-domain/same-origin security is intended to prevent.
    Monitoring user interaction with a page from a different domain, if
    successful, would be open to considerable abuse. Consider monitoring
    someone's interaction with the log-in page at their bank's web site, for
    example (if onclick then why not onkeydown, and read their user name and
    password as they type it in?).

    You shouldn't expect this desire to be achievable (and your on-line
    reading should have warned you of the issue).

    Richard.


    Comment

    • foldface@yahoo.co.uk

      #3
      Re: iframe and attachevent

      "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message news:<cke1oc$ke 3$1$8300dec7@ne ws.demon.co.uk> ...[color=blue]
      > foldface@yahoo. co.uk wrote:[color=green]
      > > Completely ignore the non-standard nature of the
      > > noddy example below.[/color]
      >
      > So long as the example actually relates to the problem.[/color]

      I've had people commenting that they won't help unless the example is
      w3
      compliant and multi-browser, bit silly for a "noddy example"
      [color=blue]
      > Find alternative reading matter.[/color]

      open to suggestions here. Problem is I only work on IE as its the only
      browser
      we support, and naturally it doesn't support everything, has bugs,
      etc. Also
      most texts I find don't seem to go into this kind of detail, and
      javascript is
      very forgiving which makes things harder for me. Perl was the same
      until I learnt about 'use strict' to make it catch more bugs.
      [color=blue]
      > You shouldn't expect this desire to be achievable (and your on-line
      > reading should have warned you of the issue).[/color]

      it did, noddy example again. The real example is all local and
      accessed (for now) via http:/localhost/Temp/temp.html, hence fine
      cross scripting wise. I'm sure that I've seen error messages from the
      browser previously though about this or I would have remembered.

      I've got this working now with something like the below

      myIFrame1.conte ntWindow.docume nt.attachEvent( 'onmousedown',
      function(){Fire Func('frame1'); })

      I don't get an 'event' object though? How do you access the x,y
      position of the mouse?

      Thanks for your help
      F

      Comment

      • Richard Cornford

        #4
        Re: iframe and attachevent

        foldface@yahoo. co.uk wrote:[color=blue]
        > Richard Cornford wrote:[color=green]
        >> foldface@yahoo. co.uk wrote:[color=darkred]
        >>> Completely ignore the non-standard nature of the
        >>> noddy example below.[/color]
        >>
        >> So long as the example actually relates to the problem.[/color]
        >
        > I've had people commenting that they won't help unless the
        > example is w3 compliant and multi-browser, bit silly for
        > a "noddy example"[/color]
        <snip>

        I can't say I have seen many people complaining that they won't help
        with IE only stuff. Unless you mean Thomas Lahn, but he is not very
        rational so you can safely disregard his opinion. It is true that IE
        only stuff gets less attention, but that is mostly because writing for
        one known environment is so trivial compared to cross-browser work that
        it isn't very interesting (so of little entertainment value).

        However, you could try posting to microsoft.publi c.scripting.jsc ript,
        where IE only questions are the natural subject of the group.
        [color=blue][color=green]
        >> You shouldn't expect this desire to be achievable (and your
        >> on-line reading should have warned you of the issue).[/color]
        >
        > it did, noddy example again. The real example is all local
        > and accessed (for now) via http:/localhost/Temp/temp.html,
        > hence fine cross scripting wise. ...[/color]
        <snip>

        That is exactly the sort of detail that needs to be presented up front
        (it would, after all, have saved me spending any time on the subject at
        all).
        [color=blue]
        > I've got this working now with something like the below
        >
        > myIFrame1.conte ntWindow.docume nt.attachEvent( 'onmousedown',
        > function(){Fire Func('frame1'); })[/color]

        Are you looking in the right place for the event object? The event will
        belong to the IFRAME's global/window object not the containing page's.
        But the attached function, and the function it is calling, do belong to
        the containing page so unqualified - event - and - window.event - both
        refer to properties of its global/window object. If you want to write IE
        only code then:-

        myIFrame1.conte ntWindow.event

        - should refer to the event object in that iframe. (Though I would
        recommend accessing IFAMEs and frames through the - frames - collection
        as the results are cross-browser (obviously works with IE as well); it
        will require less reworking when IE's market share drops to the point
        where even the most intransigent commercial sites realise they need to
        accommodate other browsers.)

        Richard.


        Comment

        Working...