Vega Discoveries Forum

Welcome Guest Search | Active Topics | Log In | Register

window.onresize - multiple handlers Options
TechGuy
#1 Posted : Thursday, February 25, 2010 11:54:39 AM
Rank: Advanced Member

Groups: Registered, Administrators

Joined: 8/17/2009
Posts: 43
As a solution gets more complex (can we say Scope Creep?) then you find yourself needing to do more and more with the same stuff.

I created a screen full of thumbnails that have a click feature that opens a popup div on the page. The popup div code uses
Code:
window.onresize = myresizedivcode;
.

This works like a charm and ensures the popup stays in the viewable area by expanding and contracting as the browser is resized.

Then we decide that we no longer want a scrollbar on the window that shows the thumbnails. This means we now place them in a div and allow the div to have a scrollbar. So, next step,
Code:
window.onresize = resizethumbdiv;
. OUCH! This works great until we click on a thumbnail and the window.onresize command gets overwritten.
After the thumb is clicked the thumbnail div no longer resizes.

So, now we need multiple handlers for the onresize event.
To do this we use attachEvent see MSDN.

Code:

attachEvent('onresize',myresizedivcode);


Xcellent - now we have multiple custom functions firing when the onresize event fires.
saviola
#2 Posted : Monday, June 14, 2010 3:48:39 AM
Rank: Welcome Guest

Groups: Registered

Joined: 6/13/2010
Posts: 4
Location: Bulgaria
With the help of event capturing you can achieve that your window, document or layer object captures the event before it is being handled by the another object(button, link etc.). Like this your window, document or layer object can handle the event before it reaches its intended target.
You can also send an event directly to a certain object. For this purpose you can use the handleEvent() method. This looks like this:

Code:
<html>
<script language="JavaScript">

window.captureEvents(Event.CLICK);

window.onclick= handle;

function handle(e) {
  document.links[1].handleEvent(e);
}

</script>
<a href="test.htm">Click on this link</a><br>
<a href="test.htm"
  onClick="alert('Event handler of second link!');">Second link</a>
</html>


The next script produce that your script can react to key events.

Code:
<html>
<script language="JavaScript">

window.captureEvents(Event.KEYPRESS);

window.onkeypress= pressed;

function pressed(e) {
  alert("Key pressed! ASCII-value: " + e.which);
}

</script>
</html>

Nothing's imposible imagination is everything!
Database Benchmark Software (GNU GPL) | World's fastest database
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Vega Discoveries Theme Created by Richard Hancock (aka-Tech Guy) (Home Page)
Powered by YAF 1.9.3 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.115 seconds.