I want to have a standard sized popup window that I can call from anywhere on the page. I'm a bit all thumbs with JavaScript but here is what I've tried. It half works, how can I better clean it up?
Also...
The header code is to contain the size, as my try below. Don't know whether to use menubar=0 or menubar=no
Any ideas greatfully accepted.
<SCRIPT LANGUAGE="Javascript1.1" TYPE="text/javascript">
<!--
function PopWindow(url){
With pop-up's all of the options are by default set to off (unless you don't have a third arguement), so you don't need all of those something=0. This script should do what you want:
Code:
<script type="text/javascript"><!--
function PopWindow(url){
window.open(url,'win','scrollbars=1, resizable=1, width=520, height=350');
}
//--></script>
</head>
<body>
<a href="target_page.html" onclick="PopWindow(this.href);return false;">This is a popup link for JavaScript enabled browsers</a>
Every fight is a food fight when you’re a cannibal.
That's just great, I've seen something similar but it was oddly coded, yours is cleaner. Out of interest, is the bit ;return false mean that if something is missing, like the URL, that it returns an error?
Just a quick translation to clear up any potential mis-understandings.
First off, the ";" is just a delimeter, it is used to put more than one JavaScript command on a line, I use it at the end of everything so that I will never get an error for missing one off. (A good habit to pick up.)
When you click a link, the following events occur in this order (as far as JavaScript is concerned):
onmousedown
onmouseup
onclick
And then when the JavaScript has finished with it, the actual clicking of the link occurs (usually taking the user to a new page).
If you use "return false" at the end of the onmousedown, onmouseup or onclick handlers it stops the link from doing what it would usually do after that particular event.
In the script I have set it so that it will open the pop-up for JavaScript enabled browsers, but JavaScript disabled browsers they will ignore the onclick attribute and just treat it as a normal link, that way everyone can see what you want to show them.
I have not used target="_blank" because that would open a new window and would therefore break the back button which would cause some users considerable confusion.
Every fight is a food fight when you’re a cannibal.
Bookmarks