473,738 Members | 5,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>
Jul 23 '05 #1
3 7369
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.getEle mentById("frame 2");

myIFrame2.attac hEvent('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.u k" 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*****@litote s.demon.co.uk> wrote in message news:<ck******* ************@ne ws.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.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
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.publi c.scripting.jsc ript,
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.conte ntWindow.docume nt.attachEvent( 'onmousedown',
function(){Fire Func('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.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.
Jul 23 '05 #4

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

Similar topics

1
2575
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 loaded and then get its title to put in the main document. function GetTitle() { var
7
9766
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. Of course, knowing, I don't want (and can't n some cases where document is generated by a cgi script) to edit every possible document which is potentially loadable in the iframe.
3
7131
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 loaded inside an iframe, knowing this document is CGI generated and that I can't modify the CGI itself (ie. add an onload event in the document body). All is said in the three HTML file I've copied below. Just create the three in same directory,...
5
3474
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 again. What I want is to take an element from an inline frame and transfer it to the parent for insertion into the parent document for display. This works just fine in FF, but of course craps out in IE. Does anyone know if there is a way to do...
4
2555
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 experience with JavaScript). Anyway, here is the code i'm working with. Basically, it creates appends a hidden IFrame to the page, gets the links from the IFrame, and displays those which have the "OnLink" property. The weird thing is that when I...
4
26739
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 using this code but I did something wrong because the temp function is fired every time the parent page loads: function temp(){ alert('the iframe was closed'); }
1
2129
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 codeHandler(e) { if(!e) e = window.event;
1
1188
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 an iframe to this, so it does the same . . . . but i'm a little unsure how to do it. thanks. TESCODIRECT.lib.topNav = new function() { this.VERSION = "1.0.0"; this.NAME = "TESCODIRECT.lib.topNav";
3
2080
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 displayed on it. Regards, Jills
0
8969
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
8788
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
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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
9208
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
8210
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
6751
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...
1
3279
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
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.