473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.getElementById("frame2");

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

<body onload=SetUp()>
<form>
<IFRAME id=frame2 src="http://www.google.co.uk" 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.html">the related document.</A>]
</IFRAME>
</form>
</body>
Jul 23 '05 #1
3 7340
fo******@yahoo.co.uk wrote:
Completely ignore the non-standard nature of the
noddy example below.
So long as the example actually relates to the problem.
I want to capture a mouse click in a frame from
outside that frame.
For which you would have to attach an event listener to the document
object within the IFRAME.
Everything I read online seems to indicate its something
like the below but I just can't get it to work. any ideas?
Find alternative reading matter.
<script>
function Temp()
{
alert('hi')
}

function SetUp()
{
var myIFrame2 = document.getElementById("frame2");

myIFrame2.attachEvent('onclick', Temp);
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.
}
</script>

<body onload=SetUp()>
<form>
<IFRAME id=frame2 src="http://www.google.co.uk" width=100%

<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.
Jul 23 '05 #2
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:<ck*******************@news.demon.co.uk>...
fo******@yahoo.co.uk wrote:
Completely ignore the non-standard nature of the
noddy example below.
So long as the example actually relates to the problem.


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"
Find alternative reading matter.
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.
You shouldn't expect this desire to be achievable (and your on-line
reading should have warned you of the issue).


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.contentWindow.document.attachEvent('onmo usedown',
function(){FireFunc('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
Jul 23 '05 #3
fo******@yahoo.co.uk wrote:
Richard Cornford wrote:
fo******@yahoo.co.uk wrote:
Completely ignore the non-standard nature of the
noddy example below.
So long as the example actually relates to the problem.


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"

<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.public.scripting.jscript,
where IE only questions are the natural subject of the group.
You shouldn't expect this desire to be achievable (and your
on-line reading should have warned you of the issue).


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

<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).
I've got this working now with something like the below

myIFrame1.contentWindow.document.attachEvent('onmo usedown',
function(){FireFunc('frame1');})


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.contentWindow.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.
Jul 23 '05 #4

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

Similar topics

1
by: Eli | last post by:
Hi, I've created a dynamic IFRAME and inserted it in the document. Then I changed the src property to some URL (not the same domain as the main document). I want to check when the IFRAME is...
7
by: Asterbing | last post by:
Hi, Talking about a js script which changes an iframe src through a "ref_to iframe.setAttribute("src", document_path);", I would like to launch a check() fct when this new document is loaded. ...
3
by: Asterbing | last post by:
Since the "on fly addition..." thread has taken another direction, I'm opening a new one to be more explicit and recenter the subject. Well, the subject is to detect when a document is well...
5
by: Logos | last post by:
I'm having trouble with this in IE; annoyingly it works beautifully in FF. My keywords are not specific enough to narrow my search to useful entries on google, way too many hits, so here I am...
4
by: Drew | last post by:
This might beyond the scope of this group because it deals with SharePoint, but I'm not sure if I can't get it to work because of SharePoint or because JavaScript is weird (I don't have much...
4
by: Mike Scirocco | last post by:
I have an iframe that includes a button: <input type="button" value="close this window" onclick="window.close();" > I would like to detect the iframe close event from the parent window, I was...
1
by: tivaelydoc | last post by:
<script language="JavaScript"> var cheatCode = "all your base are belong to us".toUpperCase(); var codeIndex = 0; function executeCheat() { alert("h4x3d!!!1!11"); } function...
1
by: cmcdermo | last post by:
We have this script that currently shows a drop down menu when someone mouseovers a link, it pulls a div that sits off the screen and shows it to the user. What i need to do now is i need to add...
3
by: Jills | last post by:
Hi All, Does anyone have any idea about how can we resize an IFRAME dynamically according to its content from another domain? I want to increase the height according to the page that is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.