473,657 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

window.event - object required.

I have this script executing
<script>
function mike_test(event )
{
x = window.event.cl ientX;
alert(x);
}
</script>
<iframe src="blank.html " id="my_iframe1" >
</iframe>

and in blank.html I have:

<div onmousedown="pa rent.mike_test( event);">
... some stuff
</div>

But I am getting "Object Required" when I execute mike_test(event );

Nov 23 '05 #1
9 6833
Remove the window from your function:

function mike_test(event )
{
var x = event.clientX;
alert(x);
}

James
http://www.logicwebstudio.com

Nov 23 '05 #2
I tried that but I get an erroreous value, I guess because the
onmousedown event is located in the iframe.

If i move the:

onmousedown="pa rent.mike_test( event);"

to the iframe like:

<iframe src="blank.html " id="my_iframe1 "
onmousedown="pa rent.mike_test( event);">
</iframe>

then it works fine.

Mike

Nov 23 '05 #3
mike wrote:
I have this script executing
<script>
The type attribute is required:

<script type="text/javascript">

function mike_test(event )
{
x = window.event.cl ientX;
IE seems to have adopted the W3C event model for iFrames.

The function is running in the parent window, so window.event (in IE)
refers to the event property of the parent window. Since no event is
fired in the parent window by a click in the iFrame, window.event is
undefined.

Using the W3C event model, you pass 'event' from the div's click event
and it goes into the function's local variable named 'event' (I think
that's confusing... but maybe that's just me) but then don't use it -
you use window.event instead.

So change the reference to the local 'event' variable and life if good
again. Incidentally, it works in IE too hence my supposition regarding
event models.

alert(x);
}
</script> [...]
But I am getting "Object Required" when I execute mike_test(event );


Change the script in the parent to:

<script type="text/javascript">

function mike_test(e)
{
var e = e || window.event; // event may come from iFrame or parent
var x = e && e.clientX; // In case e isn't defined
alert(x);
}

</script>

--
Rob
Nov 23 '05 #4
RobG wrote:
mike wrote:
I have this script executing
<script>


The type attribute is required:

<script type="text/javascript">
function mike_test(event )
{
x = window.event.cl ientX;


IE seems to have adopted the W3C event model for iFrames.

<snip>

It hasn't. remember that the event handler is defined in an HTML
attribute as:-

<div onmousedown="pa rent.mike_test( event);">

- and since the code from the attribute value becomes the body of an
event handler function that function body refers to the unqualified
identifier - event -. In W3C borrowers that identifier refers to an -
event - parameter automatically included in the generated event handler
function. In IE the identifier is resolved against the scope chain. As
the window/global object has a property called "event" the unqualified
identifier is resolved as the value of that property (assuming the name
is not masked by a property of another object on the scope chain. The
global object on the end of that event handler's scope chain is the one
belonging to the IREAME.

The - mike_test - function will be passed an event object in both
systems.

The later comment from the OP that "I get an erroneous value" probably
indicates that the clientX property is returning the X co-ordinate of
the mouse in the IFRAME's client region (as would be expected) instead
of the topmost window object's client region.

Richard.
Nov 23 '05 #5
>The later comment from the OP that "I get an erroneous value" probably
indicates that the clientX property is returning the X co-ordinate of
the mouse in the IFRAME's client region (as would be expected) instead
of the topmost window object's client region.


Yes I think Richard. is correct the X co-ordinate is wrong and it is
looking at the iframe and not the topmost window.

Sounds to me like there is not a workaround.

When I move the onmousedown event to the iframe tag then the topmost
window coordinate is seen. However, the bad is that I have nothing to
click on so it is dragable. If I add style to the iframe in terms of a
larger border, then when it is moved by a select element, the select
element occludes it. It's ugly.

So, that is why I was attempting to put the onmousedown event inside
the iframe src, but I get erroneous coordinates.

There then is the difficulty.

Nov 23 '05 #6
Richard Cornford wrote:
RobG wrote:
mike wrote:
I have this script executing
<script> The type attribute is required:

<script type="text/javascript">
function mike_test(event )
{
x = window.event.cl ientX;

IE seems to have adopted the W3C event model for iFrames.

<snip>

It hasn't. remember that the event handler is defined in an HTML
attribute as:-

<div onmousedown="pa rent.mike_test( event);">

- and since the code from the attribute value becomes the body of an
event handler function that function body refers to the unqualified
identifier - event -. In W3C borrowers that identifier refers to an -
event - parameter automatically included in the generated event handler
function. In IE the identifier is resolved against the scope chain. As
the window/global object has a property called "event" the unqualified
identifier is resolved as the value of that property (assuming the name
is not masked by a property of another object on the scope chain. The
global object on the end of that event handler's scope chain is the one
belonging to the IREAME.

The - mike_test - function will be passed an event object in both
systems.


Thanks, I forgot about in-line code, I was thinking of dynamically
attached functions.


The later comment from the OP that "I get an erroneous value" probably
indicates that the clientX property is returning the X co-ordinate of
the mouse in the IFRAME's client region (as would be expected) instead
of the topmost window object's client region.


Yes, you are right - I've posted a solution in reply to Mike.
--
Rob
Nov 23 '05 #7
mike wrote:
The later comment from the OP that "I get an erroneous value" probably
indicates that the clientX property is returning the X co-ordinate of
the mouse in the IFRAME's client region (as would be expected) instead
of the topmost window object's client region.


Yes I think Richard. is correct the X co-ordinate is wrong and it is
looking at the iframe and not the topmost window.

Sounds to me like there is not a workaround.


So you are after the coordinates of a click in the iFrame with respect
to the parent? I'm not sure why you'd need that, anyhow below is a
script that does it.

You need to add the top/left position of the iFrame to the event
coordinates. Make sure your parent body margin and padding are
specifically set to some value (zero is good), because IE does not
include the default margin and padding when getting the location of
elements.
<script type="text/javascript">

function mike_test(event )
{
var iFramePos = elPos(document. getElementById( 'my_iframe1'));
var eventPos = {x:event.client X, y:event.clientY };

alert(
'Event: ' + event.type
+ '\nCo-ords in iFrame: ' + eventPos.x + ', ' + eventPos.y
+ '\nCo-ords in parent: '
+ (eventPos.x + iFramePos.x) + ', '
+ (eventPos.y + iFramePos.y)
);

}

function elPos(el){
var pos = {x:0, y:0};
if (el.offsetParen t) {
while (el.offsetParen t) {
pos.x += el.offsetLeft;
pos.y += el.offsetTop;
el = el.offsetParent ;
}
} else if (el.x){
pos.x = el.x;
pos.y = el.y;
}
return pos;
}
</script>
--
Rob
Nov 23 '05 #8
Rob,

Are you saying that your solution about will give me that coordinates
of the iframe in relation to the top of the document?

Mike

Nov 23 '05 #9
mike wrote:
Rob,

Are you saying that your solution about will give me that coordinates
of the iframe in relation to the top of the document?


Yes, the elPos() function does that. If your iFrame scrolls, you need
to account for that in the iFrame coordinates (I haven't) but the parent
ones are good. i.e. add the scroll to the iFrame co-ords only, keep the
parent co-ords as event co-ords plus iFrame offset.

Poke around <URL:http://www.quirksmode. org>.
--
Rob
Nov 23 '05 #10

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

Similar topics

2
24769
by: gokul | last post by:
Hi all, Iam using mozilla firebird. I have three popups displayed at one point of time...if I close one the other two goes hidden....could you please suggest me the reason for this behaviour and how to overcome it..... While I opened......these child windows(popup)...from the main window I have given "dependent=yes" in the window.open statement. The sameway I want to close the Child windows opened from the parent
12
12421
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank, 'height=200,width=400,status=no,toolbar=no, menubar=no,location=no resizable=no scrollable=no'); but I can't seem to invoke the client side script from within a Server Side Form. I know I can use the context with to Response.redirect or Server.transfer to return a
4
561
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum number of window handle, because if I reduce to about 2 instances of each window, it can run. But not 20 instances of each window. Does anyone know what the problem is? is it really because it exceeds the maximum number of window handle?
9
12300
by: pow67 | last post by:
Is there a javascript statement which can be incorporated in a hyperlink which will open a new page that fills the screen while leaving the page with the link open? Thanks in advance. CW
3
5610
by: James Spibey | last post by:
Hi, I have an MDI application which has aboout 10 child windows. The way the app needs to work is that only one window should be visible at a time and it should be maximized within the parent window. I have set all my child windows to be WindowState.Maximized but after showing 2 or 3 windows, the windows all drop back to Normal state. I have tried various things to overcome this inclusing overriding OnResize etc but none seem to give...
1
11566
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
1
5402
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for that), the popup window will have also a text box and a button. when the User click on the button the value on the textbox will be send back to the textbox on My_WUC. I hope I was clear off what I want to do. I've been searching for some ideas...
2
1620
by: Bert Szoghy | last post by:
Hello, I am missing something about Visual Basic .NET module variables and window close events. In the following code, after opening Form2 by clicking a button on Form1 and then closing Form2, I would expect to click on the second Form1 button and get intMyValue = 0. Form2 has code to reinitialize it in its close event, but this doesn't seem
4
6395
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database to look a and I am loosing tremendious amounts of time trying to organize it so that I could view it. Regards, Alexandre Brisebois
0
8399
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
8312
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
8827
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
8732
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...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
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
7337
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...
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
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.