Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a new window with a defined size.

Status
Not open for further replies.

kruxty

Programmer
Jul 17, 2001
197
PT
I want to open a new window but with a determinated size.
how can i do this?

Tkx,
Krusty
 
Code:
<script type=&quot;text/javascript&quot; language=&quot;javascript&quot;>
function windowOpener(url)
window.open(url, &quot;windowname&quot;, &quot;toolbar=no, location=no, width=XXX, height=XXX&quot;,)

Code:
<A href=&quot;JavaScript:windowOpener('[URL unfurl="true"]http://www.tek-tips.com')&quot;>Click[/URL] here for Tek-Tips</a>

just play around with the settings yourself, there's a popup generator here -->
hope this helps
 
i didn't understand it verywell.
Where do i put that script?
Imagine that i have a word such as &quot;menu&quot; and i want that when the user click on that link open a window with a determinate size.
 
any javascript generally goes in the head section of the html. Then in the body, where you want the link to be just put:
Code:
<A href=&quot;JavaScript:windowOpener('[URL unfurl="true"]http://www.tek-tips.com')&quot;>Menu</A>[/URL]
This will do what you want. Rather than restircting the function to just one URL, I designed it so that you could use it again to open anohter popup the same size, but a different URL. Eg:
Code:
<A href=&quot;JavaScript:windowOpener('[URL unfurl="true"]http://www.hotmail.com')&quot;Hotmail</A>[/URL]

Depending on whether you use the windowname property or not, this will open in the same window as the previous popup, or in a new window. if the window name is the same, they'll use the same window - so if you wanted them to each open in seperate windows, just leave the windowname blank.

hope I haven't confused you with all that?
 
i continue with some problems...
As you see i don't understand anything about javascript :(
I written the code in head and put the ahref stuff inside the body, but the word that make the link don't appear...
What i'm keeping doing wrong!?
 
OK ... I guess from your other post about the windows etc that you just want one popup, correct? If so, then we can just change the function to the following:
Code:
function openSesame()
{
window.open(&quot;[URL unfurl="true"]http://www.mysite.com/popup.html&quot;,[/URL] &quot;popup_name&quot;, &quot;toolbar=no, address=no, width=150, height=150&quot;);
}

windowOpener wasn't really a very good name for a function, so I changed it!!

Now then, if you want to learn some JavaScript, is a good place to start, they've got a tutorial on JavaScript here -->
Hope this helps. If you've still confused (I know I'm not very good at explaining stuff!), post back
 
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<script type=&quot;text/javascript&quot; language=&quot;javascript&quot;>
function openSesame()
{
window.open(&quot; &quot;popup_name&quot;, &quot;toolbar=no, address=no, width=150, height=150&quot;)
}
</head>

<body>
<a href=&quot;JavaScript:eek:penSesame ('menu.htm')&quot;>Menu</a>
</body>
</html>






----------------------------------------------------------

Isn't like this?
I'm sorry for being such a !#$)/$!#&quot; but can you just help put this write?
Tkx Krusty ;o)
 
not quiet ... when you're calling it, just put
Code:
 <a href=&quot;JavaScript:openSesame()&quot;>Menu</a>

You only ever put anything between the brackets when calling a function if there's something between them when you &quot;created&quot; the function. In the first example, you'll notice I had URL between the brackets, so when I called it, I replaced URL with the actual URL. Likewise, in the second one (openSesame function) - I didn't put anything between the brackets when I &quot;created&quot; the function, so I don't put anything between them when I call it in the <A href ... but the brackets always need to be there.

God, I hope I haven't totally confused you here. Well, anyway, now you know how to call the function it'll work fine.

Don't worry about being such a !#$)/$!#&quot; - I'm glad to be able to help. It's helping me too, I don't work at this for a living so it's good to refresh my memory!!

 
The link doesn't appear at all!!?!?!?!
I'm becoming nuts...
 
what exactly do you mean? you mean the work Menu? Then you probably have a small error somewhere. can you post some code?
 
the reason why it doesn't work is because he has an error in the code that he posted at the forum....

window.open(&quot; &quot;popup_name&quot;, &quot;toolbar=no, address=no, width=150, height=150&quot;)

notice he has a semi-colon after the url, it is not supposed to be there...
 
couple of syntax errors I noticed in the code you pasted to your post, kruxty.

The elements you are missing in your code are:
- Closing the <script> tag </script>
- HTML comment tag <!-- and closing comment tag so that the browser doens't confuse script with normal HTML //-->
- i don't think it is necessary to explicitely call the script of type text and javascript. just a plain script tag will do
- the semi-colon after the first argument in the window.open function is not necessary, however you should end the function with a semi-colon

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
Code:
<script>
<!--
Code:
function openSesame()
{
window.open(&quot;[URL unfurl="true"]http://www.mysite.com/popup.html&quot;,[/URL] &quot;popup_name&quot;, &quot;toolbar=no, address=no, width=150, height=150&quot;)
Code:
;
Code:
}
Code:
 //-->
</script>
Code:
</head>

<body>
<a href=&quot;JavaScript:openSesame ('menu.htm')&quot;>Menu</a>
</body>
</html>
I've tested this code and it should work. of course the line with window.open should be all on one line. Tek-tips just automatically text/wraps... you can simply copy/paste this into an html file. (that's how I tested)
check out this website I almost exclusively use this as a reference for HTML, Javascript, ASP, ADO, and SQL...

and the specific page about the window.open function is here: Earnie Eng
If you are born once, you will die twice.
If you are born twice, you will die once
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top