473,763 Members | 5,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript across frames - notification when link is clicked

Hello!

My first post here...

I need to monitor if someone clicked on some (any) link in a subframe.
Due to certain restrictions, the only place I can put some JavaScript
is in the main (frameset) page, though.

It appears you can do somehing like document.onClic k = blah to ensure
that the function blah is called when someone clicks on a link in the
current document. But what do I need to do when I would like blah to be
called when a link in a subframe of the current document (frameset) was
clicked on?

Any help is greatly appreciated.

Thank you very much!

Tom

Jul 23 '05 #1
6 2833
Tom Braun wrote:
I need to monitor if someone clicked on some (any) link in a subframe. Due to certain restrictions, the only place I can put some JavaScript
is in the main (frameset) page, though.


Your exact meaning was unclear to me, but perhaps you are looking
for something like the below example (the important part is that
onClick="parent .clickFunc(this );return false;").

That having been said, I am curious about one thing in the example
below. In my FF 1.1, the link is not underlined if I omit the
<u> ... </u>. Have I missed something?

Csaba Gabor from Vienna

<html>
<head>
<title>Frame clicks</title>
<script type='text/javascript'>
function clickFunc(oLink ) {
alert(oLink.id + " has been clicked!"); }
</script>
</head>
<frameset>
<frame src="javascript :'<html><head>< title>Inner</title>
</head><body>
<a href=&quot;noth ing.htm&quot; id=foo
onClick=&quot;p arent.clickFunc (this);return false;&quot;>
<u>Try me</u></a></body></html>'">
</frame>
</frameset>
</body>
</html>

Jul 23 '05 #2
Tom, I think I see what you're getting at, but just to clarify: the
pages in the frame, are they on the same domain name as the parent
document (frameset)? If not, it is not feasible to monitor anything
about them. Documents from two different domains (foo.com, bar.com) are
kept strictly separate by the browser.

If they are not, then I have to wonder: why can't you put your JS in
them?

Regardless:
The best way is to attach an onClick event to the frame's document (
for instance:

window.frames[ myFrameIndex ].document.onCli ck = function () {
// figure out if it's a link and do stuff
}

; or using attachEvent )

Within the function, you will need to determine if the element clicked
was a link (this function will be called if they click ANYTHING in the
frame), for instance using its nodeName or nodeType, then do whatever
you need to do if it's a link.

Now: Assuming you allow the click to succeed... you then have to
reattach your function_ref event handler to the onClick event on the
document they click to, but you have to remember that the document will
not load immediately.

I recommend using a setInterval or setTimeout loop to check the
document's status.

Also, if for any reason the target document fails to load, your whole
deal could break altogether, so some exception handling is recommended.

Basically... the fundaments of what you're trying to do are pretty
simple:
window.frames[ myFrameIndex ].document.onCli ck = function () {
// figure out if it's a link and do stuff
}

But to really make it work right is not so easy.

Jul 23 '05 #3
Hello!
Thank you for the response. I experimented around with your
suggestion, but ran into a problem. First I tried this:

---
<html><head><ti tle>Framset</title></head>
<script type="text/javascript" language="JavaS cript">
window.frames['FS_1'].document.onCli ck = function () { alert('Test
message!'); };
</script>
<frameset cols="200,600">
<frame name="FS_1" src="fs1.html" noresize frameborder="ye s"
scrolling="no">
<frame name="FS_2" src="fs2.html" noresize frameborder="ye s"
scrolling="auto ">

</frameset>
</html>
---

When I do that I get an error: window.frames.F S_1 has no properties. I
assume this happens, because the frame is not defined at that point
yet? When I place the JavaScript AFTER the framset definition, then it
does not get executed at all.

Where do I need to place JavaScript code, which refers to subframes?

Thank you very much...

Tom

Jul 23 '05 #4
Pretty sure you're right on that one, Tom. Try moving the <script> to
the bottom, after the </frameset>, before the </html>.

Also, if I remember correctly, I believe the '.onClick' should be
'.onclick' (this was my mistake, sorry about that).

Tom Braun wrote:
Hello!
Thank you for the response. I experimented around with your
suggestion, but ran into a problem. First I tried this:

---
<html><head><ti tle>Framset</title></head>
<script type="text/javascript" language="JavaS cript">
window.frames['FS_1'].document.onCli ck = function () { alert('Test
message!'); };
</script>
<frameset cols="200,600">
<frame name="FS_1" src="fs1.html" noresize frameborder="ye s"
scrolling="no">
<frame name="FS_2" src="fs2.html" noresize frameborder="ye s"
scrolling="auto ">

</frameset>
</html>
---

When I do that I get an error: window.frames.F S_1 has no properties. I assume this happens, because the frame is not defined at that point
yet? When I place the JavaScript AFTER the framset definition, then it does not get executed at all.

Where do I need to place JavaScript code, which refers to subframes?

Thank you very much...

Tom


Jul 23 '05 #5
Hello!
It seems I need to make sure I execute the JavaScript only AFTER the
frame is loaded. That can be done like this (I'm all very new to this
and just figuring things out as I go):

---
<html><head><ti tle>Framset</title>
<script type="text/javascript" language="JavaS cript">
<!--
function blah() {
window.frames['FS_1'].document.oncli ck = function () {
alert('Test message!'); }
}
//-->
</script>
</head>
<frameset cols="200,600" onload="blah(); ">
<frame name="FS_1" src="fs1.html" noresize frameborder="ye s"
scrolling="no">
<frame name="FS_2" src="fs2.html" noresize frameborder="ye s"
scrolling="auto ">
</frameset>
</html>
---

That way, the function is defined earlier, but not executed yet. Only
once the frameset is loaded (and thus FS_1 is known) is the function
called, which refers to FS_1.

Weird, but I guess that's how it goes. Just moving the JavaScript down
below the framset does not help. In fact, I did a very simple
JavaScript, which just opened an alert() window. If the code was below
the frameset, it simply was not called. This was in Firefox. Does the
same happen in IE or other browsers? Strange.

Thank you very much for your help...

Tom

Jul 23 '05 #6
I don't really have any more input for you here, other than to say that
I never had any trouble with FF or IE executing scripts before or after
the <frameset />. I made one site that relied very heavily on scripts
defined after the </frameset>.

Glad you got it working, though.

Cheers.
Tom Braun wrote:
Hello!
It seems I need to make sure I execute the JavaScript only AFTER the
frame is loaded. That can be done like this (I'm all very new to this and just figuring things out as I go):

---
<html><head><ti tle>Framset</title>
<script type="text/javascript" language="JavaS cript">
<!--
function blah() {
window.frames['FS_1'].document.oncli ck = function () {
alert('Test message!'); }
}
//-->
</script>
</head>
<frameset cols="200,600" onload="blah(); ">
<frame name="FS_1" src="fs1.html" noresize frameborder="ye s"
scrolling="no">
<frame name="FS_2" src="fs2.html" noresize frameborder="ye s"
scrolling="auto ">
</frameset>
</html>
---

That way, the function is defined earlier, but not executed yet. Only once the frameset is loaded (and thus FS_1 is known) is the function
called, which refers to FS_1.

Weird, but I guess that's how it goes. Just moving the JavaScript down below the framset does not help. In fact, I did a very simple
JavaScript, which just opened an alert() window. If the code was below the frameset, it simply was not called. This was in Firefox. Does the same happen in IE or other browsers? Strange.

Thank you very much for your help...

Tom


Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4456
by: Steve | last post by:
Hi, I have a private website for 20 people that is similar to a web email client like hotmail. There are two frames, one on the left with links for "New", "History", "Todays" and a frame on the right with a table for viewing the contents of these messages. The left pane checks back with the server every few seconds to see if any new messages need to be processed and updates count accordingly.
9
1919
by: Dom | last post by:
I have a frameset with a left right columns, called 'index' and 'content'. The left column of the frameset ('index') loads an index.htm file which have these hrefs (summarized the code a bit) for readability : <a href="studio/index.htm" target=content id="studio"> studio </a> <a href="bandw/index.htm" target=content id="bandw"> bandw </a> <a href="arch/index.htm" target=content id="arch"> arch </a> <a href="etc/index.htm" ...
8
3674
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
3
2407
by: mportman300 | last post by:
Have pity on me.. i have been doing html, css, javascript squarely over 2 years... and am now doing a family project.. in my project i have decided to use a context menu script, its a menu that pretty much allows for when you right click on a page it shows you different links that the standard right click menu, link here: http://www.dynamicdrive.com/dynamici...ontextmenu.htm What it does exactly is opens a new window with the link that you...
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.