Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6015
  • Last Modified:

Revisited "Solution Title: <body onload=resize window, position, no toolbars, no scrollbars"

Hi.

I'm a total gimp when it comes to javascript. I want to use the code by superslamwhich and hismightyness that was discussed in the topic "Solution Title: <body onload=resize window, position, no toolbars, no scrollbars" in Aug - Sep.

I tried to just paste it in to my document head and put the onLoad part in the body. It does not work for me however. Where does the code go? Does the script tag need to change? How does it now what window to open?
Like I said I know nothing and would really appreciate a straightforward explanation and copy/paste script.

This is what I did:

<head>
      <title>MyTitle</title>
      
      <script type='text/javascript'>
function SetWindow()
{
     url = "mypage2.htm"                //Set address of new window
  var height = 600                       //Set height
  var width = 800                        //Set width
  var name = "Popup"             //Set window name
  var top = 20                            //Set distance from top
  var left = 20                            //Set distance from bottom
  newwin=window.open(url, name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
       // Cannot perform across all browsers
         this.focus();
         self.opener = this;
         self.close();
     }
}
</script>

</head>

<body onload="SetWindow();">

Need help now,
cheers.
0
iamcmag
Asked:
iamcmag
  • 6
  • 4
  • 4
2 Solutions
 
alambresCommented:
note that you got 1 { and 2 }. Remove one } and it'll go.
0
 
sajuksCommented:
//try this
<head>
     <title>MyTitle</title>
     
     <script type='text/javascript'>
function SetWindow()
{
     url = "mypage2.htm"                //Set address of new window
  var height = 600                       //Set height
  var width = 800                        //Set width
  var name = "Popup"             //Set window name
  var top = 20                            //Set distance from top
  var left = 20                            //Set distance from bottom
  newwin=window.open(url, name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
       // Cannot perform across all browsers
        this.focus();
        self.opener = this;
        self.close();
     
}
</script>

</head>

<body onload="SetWindow();">
</body>
0
 
alambresCommented:
<html>
<head>
     <title>MyTitle</title>
     
     <script type='text/javascript'>
function SetWindow()
{
  url = "mypage2.htm"                //Set address of new window
  var height = 600                       //Set height
  var width = 800                        //Set width
  var name = "Popup"             //Set window name
  var top = 20                            //Set distance from top
  var left = 20                            //Set distance from bottom
  newwin=window.open(url, name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
       // Cannot perform across all browsers
        this.focus();
        self.opener = this;
        self.close();
     
}
</script>

</head>

<body onload="SetWindow();">
</body>
</html>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
iamcmagAuthor Commented:
Thanks guys.

Since both answers came in at exactly the same time I split the points between you. I hope that you will be alright with this.

Thanks again.
0
 
iamcmagAuthor Commented:
What does the name var actually do? I thougt that would be the title of the new window but it's not.
0
 
sajuksCommented:
var  stands for variable declaration.
Its the same as DIM in asp or the way you assign string, numeric in databases.In javascript all are defined as var.
0
 
sajuksCommented:
Dont let me down guys & gals. I told my friends that you people could do anything and everything.
:-)
0
 
sajuksCommented:
ignore the above comment, too many windows open posted in the wrong thread.
0
 
iamcmagAuthor Commented:
I understand what A var is I just don't see any real use of the name var in this example. I can't see that it does anything to my new window.
0
 
sajuksCommented:
//thanks to jbirk for the expln
Basically anytime you just come up with a new variable with declaring, it gets global scope, no matter where it is.
Consider a function
function test()
{for (i=0;i<5;i++)
  test2()
}

function test2()
{for(i=5; i>=0; i--)
  //do something
}

An inifite loop occured because when the second called function assigns something to i, that affects the i in the previous function. .

By simply adding var i; to the beginning of the test2(), it's fine:
function test2()
{var i;
 for(i=5; i>=0; i--)
  //do something
}

That makes the i variable local in scope and own't interfere with the previous i.
0
 
alambresCommented:
hey sajuks !!
I think you've missed the thread again
0
 
iamcmagAuthor Commented:
Thanks for everything
:0)
0
 
sajuksCommented:
hey alambres , dont think so , dont just look at the code check the explanation too :-)
0
 
alambresCommented:
oops, sorry, maybe I need a coffee :-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now