« Q & A page
« tech pages
|
Creating a pop up window
by Mike Slocombe
Q: I'd like people to be able to click on links on my page and have another smaller pop-up window open up. How do I do this?
T Porter
A: JavaScript is the fella for this job - with a simple bit of code, you create pop up windows containing whatever code you like.
Simply slap this bit of code between the <head> </head> part of your page (it should all appear on one line):
<script type="text/javascript">
<!--
window.onerror=null; function popup(url)
{ mywin = window.open(
url,"popup",
'height=300, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no,
location=no, directories=no, status=no'); }
-->
</script>
And then create this link on your page:
<a href="javascript:popup('your_web_page.html')">your link</a>
Click here for demo
Note that I have highlighted the word 'pop up' in the code and the link. In order for the JavaScript to know what item it is dealing with, the item has to have a name. You can call it anything you like, but it has to be the same in the code and the link.
What does what:
height=300 specifies the height of the window in pixels.
width=400 specifies the width of the window in pixels.
toolbar=no denotes if there will be a toolbar on the newly opened window (the toolbar is the line of buttons at the top of your browser). Set this to yes if you want one - no if you don't.
menubar=no denotes if there will be a menubar (text menu across top of a browser with 'file', 'edit' view' etc). Set this to yes if you want one.
scrollbars=no denotes if there will be scrollbars or not.
resizable=no specifies whether the user can change the size of the window by dragging or not.
location=no specifies if there will be a location bar (text box displaying current URL) on the newly opened window.
directories=no denotes if there will be a directories bar on the new window. Use yes and no.
This is the bar at the top of the browser window that has the bookmarks and such.
status=no denotes if there will be a status bar. Use yes and no.
The status bar is the area at the very bottom of the browser screen.
More info:
JavaScript Popup window generator
HTML Goodies
Javascript pop up windows
May 2004
|