Forum Moderators: open
function newWindow(file,window) {
var msgWindow;
msgWindow=open(file,width,'resizable=no,width=1337,height=1337');
if (msgWindow.opener == null) msgWindow.opener = self;
return false;
}
Then the link side of it is:
href="javascript:void(0);" onClick="return newWindow('file.html','OMG',);"
Basically, just like the 'file' is a varible that controls which .html file gets loaded into the new window, I want to have a varible for width and height, and I tried the obvious way (mimicking the way the file varible works) and i come up with nothing.
Sorry for the nub question, thanks.
You can control url, width, height, and optionally give the window a name.
[A window popped to the same name as an already-existing window will just change that window, not open a new one, so it's useful]
The function returns a ref to the popup, so you can store it in a variable (as I have done below).
I have put the URL in the
href of the link (for non-JS browsers). The [blue]return false[/blue] is to stop this link being followed when JS is enabled and a pop opens instead.
<script>
function pop(url,width,height,name)
// optional: last arg
{
var win = window.open(
url,name,"width="+width+",height="+height+"resizable=0"
)return win
}
</script><a href = "page.htm" onclick="pop1=pop('page.htm',200,300,'win1');return false">open pop</a>
BTW, I was interested in this bit in yours:
if (msgWindow.opener == null) msgWindow.opener = self; This assigns the current window to the opener property of the pop-up. Apparently, someone believes that this isn't the default behaviour anyway. Maybe there are browsers that don't support this property - if so, it's a good idea, so maybe put it back (with the varName changed).
You could have a go at resizing the window, inside the function, using the local var:
win.resizeTo(width,height)
1. This may need to be on a v. short timed delay for some browsers.
2. I don't actually know whether these dimensions will give the same size window as when used in open (inner / outer width).
Have a go
Well you're right, they are slightly different dimensions, but I'll mess with it :)
Edit: Woo, I even figured something out myself! msgWindow.focus(); after everything else in the function causes the pop to be in focus again, which is nice. Otherwise when the user clicks it changes dimensions but stays minimized :D
Forever greatful.