View Full Version : Clicking within a frame

01-21-2006, 05:48 PM
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:



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

<body><p>This page uses frames and your browser does not support them.</p></body>



01-21-2006, 05:54 PM
On the page in the top frame:
<script type="text/javascript">
window.bottomFrameClicked = function() {
}On the page in the bottom frame:
<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:
<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.

01-21-2006, 06:12 PM
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....

01-21-2006, 06:42 PM
Yes, there's a good point:
<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();