PDA

View Full Version : open new pop up



questions
08-09-2008, 02:32 AM
Is this older code still correct for a pop-up?
I have "resize=no" down but it's letting me resize it.

I'm not an expert. I copied this from somewhere long ago.


<script type="text/javascript">
<!--
function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
if(window.screen)if(isCenter)if(isCenter=="true"){
var myLeft = (screen.width-myWidth-50)/2;
var myTop = (screen.height-myHeight-50)/2;
features+=(features!='')?',':'';
features+=',left='+myLeft+',top='+myTop;
}
window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

//-->
</script>



<a href="#" onClick="OpenBrWindow('pop.html','','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=no','634','658','true');">Pop Up.</a>

THANKS.

jscheuer1
08-09-2008, 02:42 AM
The proper specification for a new window that cannot be resized is:

resizable=0

Or, just omit resizable from the specification. However, many browsers will no longer allow a new window that isn't resizable. It's an accessibility issue.

questions
08-09-2008, 02:46 AM
THANKS!

Does the rest of it look correct?
Should all the "no" be "0"?

mburt
08-09-2008, 02:49 AM
Should all the "no" be "0"?

The rest should be fine with "no".

questions
08-09-2008, 02:49 AM
And yes, you are right, I cannot control the resize, even with 0, it still let's you resize.

Thanks.

mburt
08-09-2008, 02:54 AM
Yeah I'm pretty sure Firefox doesn't let you control the "resize" attribute, but IE might. I'm not sure.

rangana
08-09-2008, 02:55 AM
I think this is a bug on FF3, can't test on FF2 if this problem is reproducible. Tested with a simple call and resizable seems to take no effect:


<a href="#" onclick='window.open("http://www.google.com/",
"mywin", "width=500,height=300,menubar=no,location=no,resizable=no,scrollbars=no,status=no");return false;'>Test</a>

mburt
08-09-2008, 02:56 AM
Or maybe it is intended by Firefox. If the user can control the "resize" attribute, users may get annoyed by it. A website shouldn't be dependent on whether the window can resize or not.

questions
08-09-2008, 03:11 AM
Or maybe it is intended by Firefox. If the user can control the "resize" attribute, users may get annoyed by it. A website shouldn't be dependent on whether the window can resize or not.

Yeah, on FF3. It's fine if someone resizes. I think they'd only do it by mistake. I'm just trying to pop up a detail of a webpage or a zoom into an image.

jscheuer1
08-09-2008, 03:15 AM
In the specification section of the window.open() method, no and 0 are equivalent. In fact, if you specify any valid specification in the specification section of window.open, anything that you omit is considered as 0/no or default.

So let's break it down. You can do:


window.open('some.htm');

That's at the discretion of the browser, but at the very least should be a new tab, unless the page has a base href of '_self', or all pop ups are blocked.

Now:


window.open('some.htm', '_blank');

we've designated a target. What you designate has consequences. With '_blank', it should be a unique new window, not a tab unless browser settings override that.

Finally, we may add specifications:


window.open('some.htm', '_blank', 'width=400, height=350');

The moment you add any specification, the browser almost has to open a new window. And all specifications not mentioned will be either 0/no/false, or if they don't qualify as boolean (true/false), they will be the default for that browser. And, as I was saying, some browsers will not allow false for things like:

status
scrollbars
resizable

If you don't have any specifications, a window.open method will usually open a normal window, or tab. If you have specifications, they will be followed first as far as the rules governing specifications go, then ultimately as far as the user's browser will allow.

That's not to mention pop up blockers, which if set to their highest setting will block all new windows. It is because of this last fact that folks often prefer AJAX and/or lightbox type scripts. Those are generally only 'blocked' if the user has javascript disabled.

TheJoshMan
08-09-2008, 03:16 AM
why not do away with popups all together? Just use something like this:

http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm

questions
08-09-2008, 03:18 AM
It is because of this last fact that folks often prefer AJAX and/or lightbox type scripts. Those are generally only 'blocked' if the user has javascript disabled.

Oh. I should get more up to date then. Is there a place to learn to do this for someone who is still in the learning stages?

Thanks!

mburt
08-09-2008, 03:26 AM
Right here on DD there is lightbox scripts. The installation instructions are on the page, just search for it.

jscheuer1
08-09-2008, 03:45 AM
why not do away with popups all together? Just use something like this:

http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm


Right here on DD there is lightbox scripts. The installation instructions are on the page, just search for it.

Good suggestions. I prefer other, tighter code. But I learned by starting with those (all written or approved by ddadmin, whose coding style tends to be instructive).

In the end, you want to go with code that best serves the requirements of what you are trying to do, while at the same time providing as much accessibility as possible to those users whose browsers cannot run all the code. Getting to that place is generally an ongoing process. So you have to start somewhere, and proceed to somewhere else, etc. If you like learning, it's a wonderful thing. If you are looking for the ultimate answer, you're bound to feel frustrated along the line.

I'm not 'there' yet, but no one is really. All that has to be balanced against actually turning out work though.

mburt
08-09-2008, 03:28 PM
Wow that was deep man. :p

jscheuer1
08-09-2008, 05:59 PM
Wow that was deep man. :p

That wasn't dude. :p