Passing objects as a functions arguments

T

toomanyjoes

This is a script I found off this group. I'm trying to modify it.

Here is the original:
<SCRIPT type="text/javascript"><!--
function adjustMain() {
document.all.Main.style.pixelHeight=document.body.clientHeight-100;
if(navigator.userAgent.indexOf("Win") != -1) {
document.all.Main.style.pixelWidth=document.body.clientWidth-135; }
}//-->
</SCRIPT>

Pretty Straighforward it adjusts the height and width of a layer when
the window is loaded or resized. Here's the script that calls it.

<SCRIPT type="text/javascript"><!-- // IE only
if (navigator.appName == "Microsoft Internet Explorer") {
window.onload=adjustMain; window.onresize=adjustMain; }//-->
</SCRIPT>

I didn't like that the layer name "Main" was hardcoded, so I'm trying
to make it more reusable. By passing more arguments and then looping
through the argument names and applying the same settings to each
layer.

Here's what I wrote:

function adjustMain() {
var layerArgs = adjustMain.arguments;
for (i=0; i<layerArgs.length;i++) {
document.all.layerArgs.style.pixelHeight=document.body.clientHeight-58;
if(navigator.userAgent.indexOf("Win") != -1) {
document.all.layerArgs.style.pixelWidth=document.body.clientWidth-50;
}
}
}

And here's what I wrote to call it:

if (navigator.appName == "Microsoft Internet Explorer") {
window.onload=adjustMain('WindowOne', 'WindowTwo');
window.onresize=adjustMain('WindowOne', 'WindowTwo'); }

It doesn't work and I think I know why, I'm passing it a string so it
cannot apply the style changes. I'm new to this is it painfully
obvious what I'm doing wrong? Can anyone help?


Thanks,

Gabriel Elizondo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top