SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A pop-up event driver question?

    Hi
    I've been reading the book "JavaScript the definitive guide" to learn more about JavaScript. In this book he gives an example function to create pop-ups. The example function is in the code posted below. This function is shown in the book without examples of how you evoke it. So I added a little more code to try it. When I evoke it was a onclick event to function works fine however when I evoke it with a mouseover event (see commented out code in posting) the firebug debugger generates this error "w has no properties [Break on this error] var d = w.document; // Get its Document object DynamicContent.ht... (line 13)". So why does evoking this function was an onclick event work while evoking it with an onmouseover event fail?
    Sincerely
    Marc

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>JavaScript Window Open Example</title>
    	<link rel="STYLESHEET" type="text/css" href="/style/jsc.css">
    <script language="javascript" type="text/javascript">
    <!--
    // This function opens a pop-up window. Invoke it from an event handler
    // or the pop up will probably be blocked.
    function hello() {
        var w = window.open();             //    Create a new window with no content
        var d = w.document;                // Get its Document object
        d.open();                             // Start a new document (optional)
        d.write("<h1>Hello world!</h1>");  // Output document content
        d.close();                           // End the document
    }
    window.onload = function(){
    document.getElementById("helloID").onclick=hello; 
    //document.getElementById("helloID").onmouseover=hello;	
    };
    </script>	
    </head>
    
    <body>
    <a href="#" id="helloID">Link to popup</a>
    </body>
    </html>

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MarcMiller View Post
    So why does evoking this function was an onclick event work while evoking it with an onmouseover event fail?
    It's classed as an unrequested popup, and probably gets blocked for that reason.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does that answer the firebug error report part of my question? Does firebug care about this class stuff? why is onclick classed as requested and onmouseover not classed that way? And where can I find out more about how requests are classed in Firefox and Internet Explorer?
    Thanks
    Marc

  4. #4
    Non-Member
    Join Date
    Aug 2006
    Location
    Kansas City
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try something like so....


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <title>JavaScript Window Open Example</title>
    <link rel="STYLESHEET" type="text/css" href="/style/jsc.css">
    <script language="javascript" type="text/javascript">
    <!--
    // This function opens a pop-up window. Invoke it from an event handler
    // or the pop up will probably be blocked.
    var hello = function() {


    alert("My Popup");


    };


    function intilize()
    {
    var MyHello = document.getElementById("helloID");
    MyHello.attachEvent("onmouseover", hello);

    }

    </script>
    </head>

    <body onLoad="intilize()">
    <a href="#" id="helloID">Link to popup</a>
    </body>
    </html>

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by like so? if I just cut and paste your code and try at it does not work.
    Last edited by MarcMiller; Jul 11, 2007 at 20:35. Reason: so

  6. #6
    Non-Member
    Join Date
    Aug 2006
    Location
    Kansas City
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't know what to say....it works on my end. Just tested it.

  7. #7
    Non-Member
    Join Date
    Aug 2006
    Location
    Kansas City
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My bad Marc. It works on IE 7 and NOT on FireFox.

  8. #8
    Non-Member
    Join Date
    Aug 2006
    Location
    Kansas City
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might not be the ideal solution, as browsers might block it, here it works in IE and FireFox....

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <title>JavaScript Window Open Example</title>
    <link rel="STYLESHEET" type="text/css" href="/style/jsc.css">
    <script language="javascript" type="text/javascript">


    function genopenpopup(url, width, height) {
    winpops = window.open(url, "",
    "width=" + (width||900) +
    ",height=" + (height||750) +
    ",scrollbars,resizable,");
    if (winpops) {
    winpops.focus();
    }
    }
    </script>
    </head>
    <body>
    <a href="http://www.google.com" onmouseover="genopenpopup(this.href);style.cursor='hand';">
    Go to this URL</a>
    </body>
    </html>

  9. #9
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the code I posted on the very top of the thread worked on onclick. I am still not see the code given to me directly above working. Does anybody know why the onclick is classified differently by Firefox then onmouseover if that is indeed the case. I am trying the code directly above from Aptana IDE built-in server and not posting its to my webspace, but the code on the very top of this thread works that way on that onclick event. Also where is the hello message in the code above?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •