Advanced Search

Results 1 to 4 of 4

Thread: Clicking within a frame

  1. #1
    Join Date
    Jan 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Clicking within a frame

    Would it be possible to have javascript detect if anything is clicked within a frame in a 2 frame window?

    Such as this example:

    Have a window open that is divided into 2 frames, a top and bottom. Would it be possible for the top frame to contain a script to know if anything has been clicked within the bottom frame's contents?

    or I could have have a page open a new window and report back to the first page if anything has been clicked within the new window?

    I am running a page exchange and would like to implement the feature of knowing if a member actually clicks on any links within the page that is being displayed.

    Any thoughts are GREATLY appreciated.


    Here is my example frame window:

    PHP Code:
    <html>

    <
    head><title>Site</title></head>

    <
    frameset rows="45,*" framespacing="0" border="0" frameborder="0">

        <
    frame name="top" scrolling="no" noresize src="topframe.php">
        
        <
    frame name="bottom" noresize SCROLLING="yes" src="http://www.SiteThatIWantToKnowIfClickedOn.com">
            
        <
    noframes>
        <
    body><p>This page uses frames and your browser does not support them.</p></body>
        </
    noframes>

    </
    frameset>

    </
    html

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    On the page in the top frame:
    Code:
    <script type="text/javascript">
    window.bottomFrameClicked = function() {
      alert("Clicked!");
    }
    On the page in the bottom frame:
    Code:
    <body onclick="parent.top.bottomFrameClicked();">
    However, from the look of the code you provided, you don't have access to the body of the second page. You might be able to do something like this:
    Code:
    <frame name="bottom" noresize="true" scrolling="yes" src="http://www.SiteThatIWantToKnowIfClickedOn.com" onclick="top.bottomFrameClicked();" />
    However, I don't know if it'll work - it may be overridden by the body of the second page.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Twey,
    Hmm well I would see how that can work, but I cannot change the body tag of the site that will appear in the bottom frame...
    I know php can replace a string with something else.. is there a way javascript can do that? Like change the contents of the site in the bottom frame? Maybe we could add a "onunlod" type tag within the body tag of the site....

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes, there's a good point:
    Code:
    <frame name="bottom" noresize="true" scrolling="yes" src="http://www.SiteThatIWantToKnowIfClickedOn.com" />
    <script type="text/javascript">
    (var g = function(){
      if(typeof document.getElementsByName("bottom")[0].document.body == "undefined") setTimeout("g()", 10);
      else document.getElementsByName("bottom")[0].body.onload = document.getElementsByName("top")[0].bottomFrameClicked();
    })();
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •