...

View Full Version : Onload help



hughesmi
08-04-2008, 11:29 PM
Hi all. I am trying to get this code to auto load but I am not getting very far. Can anyone help?





<!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>

ninnypants
08-04-2008, 11:41 PM
<body onload="loadme();">

Is that what your problem was or do you need to preload variables?

hughesmi
08-05-2008, 03:07 PM
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


<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]




<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()">

ninnypants
08-05-2008, 04:48 PM
I beleive it's because you have a few errors in your script, and I have them marked in red:


<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

hughesmi
08-05-2008, 07:00 PM
Hey thanks for the help but it still has an errror, it's saying an "object expected" on line 39.

This one
<body onload="javascript:goNewWin()">

ninnypants
08-05-2008, 07:06 PM
Did you try Changing:

<body onload="javascript:goNewWin()">
to this:

<body onload="goNewWin();">

hughesmi
08-05-2008, 07:10 PM
No, same prob'

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



<!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>

ninnypants
08-05-2008, 07:17 PM
Just noticed:


// 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


// Set height and width
var NewWinHeight='450px';
var NewWinWidth='380px';

// Place the window
var NewWinPutX='150px';
var NewWinPutY='150px';

hughesmi
08-05-2008, 07:29 PM
No joy, same probs

ninnypants
08-05-2008, 07:37 PM
What are you trying to do with this section?


if (!TheNewWin.opener)
TheNewWin.opener = self;

hughesmi
08-05-2008, 07:43 PM
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

ninnypants
08-05-2008, 07:53 PM
Try these or even getting rid of this completely other than that I don't have any other ideas

if (TheNewWin.opener)
TheNewWin.opener = self;

if (!TheNewWin)
TheNewWin.opener = self;

rangana
08-06-2008, 04:57 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum