Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: Onload help

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Onload help

    Hi all. I am trying to get this code to auto load but I am not getting very far. Can anyone help?



    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>GreyBox - Normal usage</title>
    
        <script type="text/javascript">
            var GB_ROOT_DIR = "./greybox/";
        </script>
    
        <script type="text/javascript" src="greybox/AJS.js"></script>
        <script type="text/javascript" src="greybox/AJS_fx.js"></script>
        <script type="text/javascript" src="greybox/gb_scripts.js"></script>
        <link href="greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" />
    
    </head>
    <script type="javascript">
    function loadme()
    {
    	this is where I am stuck
    	}
    <body onload="loadme">
    
    <a href="http://google.com/" title="Google" rel="gb_page_center[500, 500]">Launch Google.com</a>
    
    
    
    </body>
    </html>
    Kind regards,
    Mike Hughes

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Code:
    <body onload="loadme();">
    Is that what your problem was or do you need to preload variables?

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    I really should explain myself more clearly. I’m trying to get my lightbox script to auto open when my page loads.

    This is the code that runs the script
    Code:
    <a href="http://google.com/" title="Google" rel="gb_page_center[500, 500]">Launch Google.com</a>
    I know I could use something like this, but the the code chucks an error becase it does'nt like these these bits of my code
    http://google.com/" title="Google" rel="gb_page_center[500, 500]
    Code:
    <script language="javascript"> 
    function goNewWin() {
    
    // Set height and width
    var NewWinHeight=450;
    var NewWinWidth=380;
    
    // Place the window
    var NewWinPutX=150;
    var NewWinPutY=150;
    
    TheNewWin=window.open("http://google.com/" title="Google" rel="gb_page_center[500, 500]"'); 
    
    //Get what is above onto one line
    TheNewWin.resizeTo(NewWinHeight,NewWinWidth);
    TheNewWin.moveTo(NewWinPutX,NewWinPutY);
    
    if (!TheNewWin.opener)
        TheNewWin.opener = self;
    }
    </script>
    <body onLoad="Javascript: goNewWin()">
    Last edited by hughesmi; 08-05-2008 at 02:09 PM.
    Kind regards,
    Mike Hughes

  • #4
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    I beleive it's because you have a few errors in your script, and I have them marked in red:
    Code:
    <script language="text/javascript"> 
    function goNewWin() {
    
    // Set height and width
    var NewWinHeight=450;
    var NewWinWidth=380;
    
    // Place the window
    var NewWinPutX=150;
    var NewWinPutY=150;
    
    //TheNewWin=window.open("http://google.com/" title="Google" rel="gb_page_center[500, 500]"'); 
    TheNewWin = window.open('http://www.google.com/','Google');
    //Get what is above onto one line
    TheNewWin.resizeTo(NewWinHeight,NewWinWidth);
    TheNewWin.moveTo(NewWinPutX,NewWinPutY);
    
    if (!TheNewWin.opener)
        TheNewWin.opener = self;
    }
    </script>
    <body onload="javascript: goNewWin()">
    On your window.open you were structuring the input wrong all it needs is the address and the name of the new window.
    Then with your 'onload' event handler you put 'javascript:' which is not needed because if you use an event handler such as 'onload', 'onclick', or 'onmouseover' the browser will already know that it is javascript

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Hey thanks for the help but it still has an errror, it's saying an "object expected" on line 39.

    This one
    Code:
    <body onload="javascript:goNewWin()">
    Kind regards,
    Mike Hughes

  • #6
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Did you try Changing:
    Code:
    <body onload="javascript:goNewWin()">
    to this:
    Code:
    <body onload="goNewWin();">

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    No, same prob'

    Here is my full code, maybe it will help more.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>GreyBox - Normal usage</title>
    
        <script type="text/javascript">
            var GB_ROOT_DIR = "./greybox/";
        </script>
    
        <script type="text/javascript" src="greybox/AJS.js"></script>
        <script type="text/javascript" src="greybox/AJS_fx.js"></script>
        <script type="text/javascript" src="greybox/gb_scripts.js"></script>
        <link href="greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" />
    
    <script language="text/javascript"> 
    function goNewWin() {
    
    // Set height and width
    var NewWinHeight=450;
    var NewWinWidth=380;
    
    // Place the window
    var NewWinPutX=150;
    var NewWinPutY=150;
    
    //TheNewWin=window.open("http://google.com/" title="Google" rel="gb_page_center[500, 500]"'); 
    TheNewWin = window.open('http://www.google.com/','Google');
    
    //Get what is above onto one line
    TheNewWin.resizeTo(NewWinHeight,NewWinWidth);
    TheNewWin.moveTo(NewWinPutX,NewWinPutY);
    
    if (!TheNewWin.opener)
        TheNewWin.opener = self;
    }
    </script>
    
    </head>
    <body onload="goNewWin();">
    
    </body>
    </html>
    
    Kind regards,
    Mike Hughes

  • #8
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Just noticed:
    Code:
    // Set height and width
    var NewWinHeight=450;
    var NewWinWidth=380;
    
    // Place the window
    var NewWinPutX=150;
    var NewWinPutY=150;
    These values have to be in quotes you may need to add a 'px' to the end but I'm not sure that the 'px' are correct or needed but the quotes are
    Code:
    // Set height and width
    var NewWinHeight='450px';
    var NewWinWidth='380px';
    
    // Place the window
    var NewWinPutX='150px';
    var NewWinPutY='150px';

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    No joy, same probs
    Kind regards,
    Mike Hughes

  • #10
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    What are you trying to do with this section?
    Code:
    if (!TheNewWin.opener)
        TheNewWin.opener = self;

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    You got me there! I just picked the JS up on the web. I just trying to mod it so i can get it do what I neeed.

    If you can point me to a better soultion then this can be scraped
    Kind regards,
    Mike Hughes

  • #12
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Try these or even getting rid of this completely other than that I don't have any other ideas
    Code:
    if (TheNewWin.opener)
        TheNewWin.opener = self;
    
    if (!TheNewWin)
        TheNewWin.opener = self;

  • #13
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Please provide a link to where you get the greybox. We might need to spoof the event on onmouseover. I believe there's no easy way on doing this since the script (as far as most lightbox i've worked with) loops through all the <a> tag, and finds the rel attribute.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

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