javascript - Handle keyPress Accross Frames in IE -


I'm trying to handle the onkeydown event on many frames (no, I'm unfortunately Can not get rid of the frame via Javascript) (See my previous question) I am handling one document on the second frame, and setting the handler to turn it on equal to my function. No error has been thrown, but when I later check the settings of the document, onkeydown is zero. I have achieved similar results in IE 6 and IE 7 . What I am doing.

  •   function setKey Hook (doc) {try {if (doc) if (parent.TOP.handleKeypress) {Doc.onkeydown = Parent.TOP.handleKeypress; Log message ('Attendor handler'); } And {log message ('no handle's receptors'); } And log message ('no doctor'); } Hold (ex) {log message (ex.toString ()); }}  
  • call

    setTimeout ("setKeyHook (parent.document.getElementById (\" down \ ").);" , 1000);

  • Output

 Attachment handler 
  • After execution
  • < / Ul>
     BOTTOM.protocol = Hypertext Transfer Protocol BOTTOM.onkeypress = null BOTTOM.onrowenter = null BOTTOM.onmousedown = null 

    How do I apply the same event handler to frames?

    Note: It requires (and only work) to work in IE6 and IE7.

I got to do this work

frameset.html

  & lt ;! DOCTYPE html public "- // W3C // DTD HTML 4.01 frameset // n http: //www.w3.org/TR/html4/frameset.dtd"> & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Test & lt; / Title & gt; & Lt; / Head & gt; & Lt; Frameset rows = "50%, 50%" & gt; & Lt; Frame src = "frame1.html" name = "top" & gt; & Lt; Frame src = "frame2.html" name = "bottom" & gt; & Lt; / Frameset & gt; & Lt; / Html & gt;  

frame 1.html

   gt; & lt; / head> gt; body & gt; frame 1 and lt; textair id = "output" & gt; & lt; / textarea & Gt; &   

frame 2.html

  & lt ;! DOCTYPE html public "- / / W3C // DTD HTML 4.01 Frameset // N "http: // www.w3.org/TR/html4/frameset.dtd"> & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Frame 2 & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; Frame 2 & lt; Textile & gt; & Lt; / Textarea & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

First of all, it always clearly clearly pays with your object references. Using proprietary DOM shortcuts (such as Window. Frame Name ) simply add unnecessary error potential, which is why my script is clearly visible in the Frame collection of window objects.

The next is to familiarize yourself with various underlying window references in the DOM, when framesets. 4 total

  1. windows - is the current window.
  2. Parents - Currently the parent window
  3. Also contained when it's left (i.e., window.onload === Onlineload ) Top - Top window in frameset family. Parents === Top when you have only one frameset.
  4. Self - Window strong>

So what I originally did here, when the frame 1 In the window, if the download event is set to fire, then in the two frames, a handler function adds a handler function to the key down event.

This function uses a shutdown to ensure that the event generated in the frame1 is available for the actual handler even if the window has generated keydown event. How is this necessary because IE does the event while other browsers create new event objects, as they are and transmit them to event handlers, IE only modifies the global event object ( window.event Or more simple, simply event ) to reflect the current event.

I hope that makes sense.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -