popup open problem only with firefox

M

Markus

Hi,

i have this problem:

Sometimes, i can't reproduce, if i click on an small image on the
website, the popup _AND_ an other Tab in firefox open.

Here are the linkcode:

<div align="center">
<a href="/screenshot?show=p4_7ghz_memesama_big.jpg"
onclick="popup(this, 850, 800); return false" target="_blank"><img
class="newspic_click" src="/newspics/p4_7ghz_memesama.jpg" alt="Bild"
title="Zum vergrößern klicken"></a>
</div>

Where? http://www.tweakpc.de/?news_id=8100 here for example

Why can this happen ? I have tried a lot, but nothing works.
 
A

ASM

Markus said:
Hi,

i have this problem:

Sometimes, i can't reproduce, if i click on an small image on the
website, the popup _AND_ an other Tab in firefox open.

your code in my FF (where I allow to open popups send from links)
open two new blank pages ... ! (and no other tab)
one naked and one complete
Here are the linkcode:

<div align="center">
<a href="/screenshot?show=p4_7ghz_memesama_big.jpg"
onclick="popup(this, 850, 800); return false" target="_blank"><img
class="newspic_click" src="/newspics/p4_7ghz_memesama.jpg" alt="Bild"
title="Zum vergrößern klicken"></a>
</div>

what does exactly your function popup() ?
what is 'this' for the function popup() in :
onclick="popup(this, 850, 800); ?
Where? http://www.tweakpc.de/?news_id=8100 here for example

Why can this happen ? I have tried a lot, but nothing works.

function popup(lnk,wiz,higt) {
here=window.open(lnk.href,'here','width='+wiz+',height='+higt+',resizable=1');
//------------------------^----^ here = the target
}

<a href="big.jpg" target="here" onclick="popup(this,850,screen.height-40)">

will open the page hrefered in links in a new naked window targeted
with same name as called in link ( target -> 'here' )
So ... no need of 'return false'

If JS is disabled, that will open a blank standard window

If popups are disabled in FF, I hope that it will open a new tab ... (?)
 
M

Markus

ASM said:
your code in my FF (where I allow to open popups send from links)
open two new blank pages ... ! (and no other tab)
one naked and one complete

Did you checked the link i posted in my first entry ? There is link to
a news with a small image that can be enlarged by clicking the picture.
What happend on your PC?
what does exactly your function popup() ?
what is 'this' for the function popup() in :
onclick="popup(this, 850, 800); ?

ok i forgot to insert the hole Script. Here it is:

function popup(element, width, height) {
if (element.getAttribute) {
url = element.getAttribute('href');
} else {
url = element;
}
new_window = window.open(url, '_blank', 'width=' + width + ', height='
+ height + ', left=' + Math.round((screen.width - width)/2) + ', top='
+ Math.round((screen.height - height)/4) + ', location=0, statusbar=0,
menubar=0, toolbar=0, scrollbars=1, resizable=yes');
}

If Javascript is enabled it should be there one new window with witdh
of 850 and height of 800. And if javascript disabled the big picture
should be open in an fresh ne window (target="_blank").
<a href="big.jpg" target="here" onclick="popup(this,850,screen.height-40)">

will open the page hrefered in links in a new naked window targeted
with same name as called in link ( target -> 'here' )
So ... no need of 'return false'
Dont understand ? the part _return false_ is used if javascript is
enabled to prevent the browser to open the new site in an extra new
full window.
If JS is disabled, that will open a blank standard window
yes.

Ok i hope now its clear.
 
A

ASM

Markus said:
Did you checked the link i posted in my first entry ?

I did this :
http://www.tweakpc.de/?news_id=8100
link :
<a href="/screenshot?show=p4_7ghz_memesama_big.jpg"
onclick="popup(this, 900, 800); return false" target="_blank"><img
class="newspic_click" src="/newspics/p4_7ghz_memesama.jpg" alt="Bild"
title="Zum vergr&ouml;&szlig;ern klicken" /> said:
What happend on your PC?

I have a Mac :-/
and obtain 2 new windows (with big jpg and some moving decorations)
one in "normal" blank
other by window.open()
ok i forgot to insert the hole Script. Here it is:

function popup(element, width, height) {
if (element.getAttribute) {
url = element.getAttribute('href');
} else {
url = element;
}
new_window = window.open(url, '_blank', 'width=' + width + ', height='
+ height + ', left=' + Math.round((screen.width - width)/2) + ', top='
+ Math.round((screen.height - height)/4) + ', location=0, statusbar=0,
menubar=0, toolbar=0, scrollbars=1, resizable=yes');
}

it is status and not statusbar
try to do not have spaces in the attributes of window.open()
If Javascript is enabled it should be there one new window with witdh
of 850 and height of 800. And if javascript disabled the big picture
should be open in an fresh ne window (target="_blank").

It seems it would have to ...
Perhaps, if you could try giving same target (as you do)
- to the link
- to the window.open()
but with a real name insteed of "_blank" (i.e : "somewhere")

It also would be interresting you see what exactly does :
screenshot?show=
Dont understand ? the part _return false_ is used if javascript is
enabled to prevent the browser to open the new site in an extra new
full window.

Yes usualy, but you use "_blank" as target in your popup ...
try without target in your popup function :
new_window = window.open(element.href,'',' blah blah ');

and ... I made a mistake :
to do not have blank window AND popup you would have to do :

function popup(width,height) {
new_window = window.open('','truc','width=' + width + ',height='
+ height + ', left=' + Math.round((screen.width - width)/2) + ',top='
+ Math.round((screen.height - height)/4) +
',location=0,status=0,menubar=0,toolbar=0,scrollbars=1,resizable=1');
}

and your link would have to be :

<a href="/screenshot?show=p4_7ghz_memesama_big.jpg"

target="truc"

Ok i hope now its clear.

your post was clear

the JS result of your link not too much :-/

my example (based on your JS) is here :
http://perso.wanadoo.fr/stephane.moriaux/truc/popup.htm
(it works fine with my FF)
 
M

Markus

ASM said:
I have a Mac :-/
sorry! ;) I forgot to check it on my one. Primary i use a pc.
It also would be interresting you see what exactly does :
screenshot?show=
This php file only build the entire popup website with the image of the
php paramter.
to do not have blank window AND popup you would have to do :

function popup(width,height) {
new_window = window.open('','truc','width=' + width + ',height='
+ height + ', left=' + Math.round((screen.width - width)/2) + ',top='
+ Math.round((screen.height - height)/4) +
',location=0,status=0,menubar=0,toolbar=0,scrollbars=1,resizable=1');
}

and your link would have to be :

<a href="/screenshot?show=p4_7ghz_memesama_big.jpg"

target="truc"

onclick="popup(850,800)"><img src=" ...></a>

GREAT it works!, but what happened to my elemt.get... code ? Can't
understand why there is no need for. How the browser know, witch File
he have to open ?
my example (based on your JS) is here :
http://perso.wanadoo.fr/stephane.moriaux/truc/popup.htm
(it works fine with my FF)

Thank you very much! Wow what a result of a long day. Just entered the
google-groups and posted a question, and hours later i have the answer
i searching since days :)
ok gn8 (4:15 am)
 
G

Gérard Talbot

Markus a écrit :
ASM wrote:




Did you checked the link i posted in my first entry ? There is link to
a news with a small image that can be enlarged by clicking the picture.
What happend on your PC?

You can avoid the forking in the popup function by making
onclick="popup(this.href, 850, 800); return false;"
instead

<img
ok i forgot to insert the hole Script. Here it is:

function popup(element, width, height) {
if (element.getAttribute) {
url = element.getAttribute('href');
} else {
url = element;
}
new_window = window.open(url, '_blank', 'width=' + width + ', height='
+ height + ', left=' + Math.round((screen.width - width)/2) + ', top='
+ Math.round((screen.height - height)/4) + ', location=0, statusbar=0,
menubar=0, toolbar=0, scrollbars=1, resizable=yes');


1- new_window should be properly declared as a global variable
2- you can replace '_blank' with a parameter transferring, copying the
target attribute value. This makes your function better parameterized,
reusable.
3- there must not be any blank space in the windowFeatures string list.
Here, you have one between each of the commas and the following name of
the windowFeature. This will break in Firefox and other Mozilla-based
browsers.
4- because of your blank spaces, scrollbars and resizable requests of
the window.open() call will be ignored
5- You request an height of 800px: that will fail in a very wide
majority of cases because a majority of 1024x768 users have about 660px
or less of available space for a window. So not only the window's top
will be reset by Mozilla/Firefox compensating positioning code, but your
window will not be 800 either.
6- do not use screen.width in any of your calculation; use
screen.availWidth and screen.availHeight since you have no idea of what
the user has in terms of semi-permanent os-dependent applications
(taskbar, MS-Magnification, Office quick launch bar, etc)
7- you make your call calculate top and left position but for
efficiency, best is to use a percentage of screen.availWidth and
screenAvailHeight
8- Hint: only declare the windowFeatures which are requested, not the
ones you want to turn off, to disable
http://developer.mozilla.org/en/docs/DOM:window.open#Examples
}

If Javascript is enabled it should be there one new window with witdh
of 850 and height of 800. And if javascript disabled the big picture
should be open in an fresh ne window (target="_blank").

If you want a complete, recommendable and working example, use this document

http://developer.mozilla.org/en/docs/DOM:window.open

and this example

http://developer.mozilla.org/en/docs/DOM:window.open#Best_practices

Dont understand ? the part _return false_ is used if javascript is
enabled to prevent the browser to open the new site in an extra new
full window.

Correct.


yes.

Ok i hope now its clear.

Gérard
 
A

ASM

Markus said:
This php file only build the entire popup website with the image of the
php paramter.
ok

GREAT it works!, but what happened to my elemt.get... code ? Can't
understand why there is no need for. How the browser know, witch File
he have to open ?

it is almost a standard html :

<a href="big.jpg" target="what_you_want">

will open file 'big.jpg' in the specified target

where is this target 'what_you_want' ?
in the window of popup launched on click ...

so ... what browser will do ?

... apply basically what it is made to :)


If JS disabled, 'what_you_want' is unknown.
Because target is not '_self' nor '_top' or '_parent'
... no other choice than to create a new blank window
to receive the file
 
A

ASM

Markus said:
There is one probleme now: It don't work with IE :(. Now, i have to
find a solution.

stil on Mac ... with :
- IE5.2 -> OK

- Opera 8.0.1
- Safari
- iCab 3.0
- etc ...
... all OK

what's wrong with your IE ?
 
R

RobG

ASM said:
witch part of the thread ?

The broomstick riding part ;-)
and what in this part ?

The thread discusses opening links in a new window so that if
JavaScript is available it will be used, and if not, then the default
HTML method is used. I didn't want to waste time re-writing stuff
that was covered just a couple of days ago.

It's difficult to tell from this thread exactly what the OP's issue
is, I figured a bit of further reading may help.
 
A

ASM

RobG said:
It's difficult to tell from this thread exactly what the OP's issue is,

It is only because in this thread was overall exposed the "return false"
that I don't use in my example :
http://perso.wanadoo.fr/stephane.moriaux/truc/popup.htm
and that seems to do not work with IE Win (I can't verify on my Mac)
Really doesn't it work with IE6 Win xp?
I figured a bit of further reading may help.

Certainly.
In original post (here) the test url had a 'return false' without effect
http://www.tweakpc.de/?news_id=8100
curious ... no ?
 
M

Markus

Hi Guys !

It works now. I found a solution and here it is:

Step 1: (inside header of website)
=====

Here is the part why ASM solution works sometimes and sometimes not:
In HEAD of my page i found this:

false
<script language="javascript" src="myscript.js"></script>

BUT true is:
<script type="text/javascript" language="javascript1.4"
src="/scripts/js/tweakpc.js"></script>

First mistake -> fixed!

Step 2: (inside mysript.js)
=====

Now i use the Code from Stephane. Thx again.

function popup(width,height)
{
new_window = window.open('','popup','width=' + width + ',height=' +
height + ', left=' + Math.round((screen.width - width)/2) + ',top=' +
Math.round((screen.height - height)/4) +
',location=0,status=0,menubar=0,toolbar=0,scrollbars=1,resizable=1,');
return false;
}

2nd mistake -> fixed too!

Step3: (insite conted of website)
=====

The right linkcode is:

<div align="center">
<a href="/screenshot?show=macosx_intel_big.gif" target="popup"
onclick="popup(this, 900, 800); return false">
<img class="newspic_click_center" src="/newspics/macosx_intel.gif"
alt="Bild" title="Zum vergrößern klicken">
</a>
</div>

3rd mistake -> fixed too!

The summary
==========

It works fine at Mac OS X Tiger with Mozilla Firefox 1.0.6 and Safari
and at Windows XP with Mi****t Internet Explorer 6 and Mozilla Firefox
1.0.6.
 
A

ASM

Markus said:
The right linkcode is:

<div align="center">
<a href="/screenshot?show=macosx_intel_big.gif" target="popup"
onclick="popup(this, 900, 800); return false">

don't understand :
scripted function is different from called function
function popup(width,height) { }
onclick="popup(this, 900, 800);
 
M

Markus

ASM said:
don't understand :
scripted function is different from called function
function popup(width,height) { }
onclick="popup(this, 900, 800);

oh, sorry. my mstake. That was an old code. The present code have no
_this_.

thx.
 
M

Markus

Gérard Talbot said:
1- new_window should be properly declared as a global variable done

2- you can replace '_blank' with a parameter transferring, copying the
target attribute value. This makes your function better parameterized,
reusable. done

3- there must not be any blank space in the windowFeatures string list.
Here, you have one between each of the commas and the following name of
the windowFeature. This will break in Firefox and other Mozilla-based
browsers.
4- because of your blank spaces, scrollbars and resizable requests of
the window.open() call will be ignored done

5- You request an height of 800px: that will fail in a very wide
majority of cases because a majority of 1024x768 users have about 660px
or less of available space for a window. So not only the window's top
will be reset by Mozilla/Firefox compensating positioning code, but your
window will not be 800 either.
This size will be ok. Our visitors have this huge resolution. We see
that on our stats.
6- do not use screen.width in any of your calculation; use
screen.availWidth and screen.availHeight since you have no idea of what
the user has in terms of semi-permanent os-dependent applications
(taskbar, MS-Magnification, Office quick launch bar, etc) done

7- you make your call calculate top and left position but for
efficiency, best is to use a percentage of screen.availWidth and
screenAvailHeight
Can you give me an example ? The new code is at the end of this posting
8- Hint: only declare the windowFeatures which are requested, not the
ones you want to turn off, to disable done

If you want a complete, recommendable and working example, use this document
http://developer.mozilla.org/en/docs/DOM:window.open
Thanks very much! :)

==========
Code start

var new_window = null;
var url = null;
function popup(element, width, height)
{
if (new_window == null || new_window.closed )
{
if (element.getAttribute)
{
url = element.getAttribute('href');
}
else
{
url = element;
}
new_window = window.open(url, 'tpc', 'width=' + width + ', height='+
height + ', left=' + Math.round((screen.availWidth - width)/2) + ',
top=' + Math.round((screen.availHeight - height)/4) +
',scrollbars=1,resizable=yes');
return false;
}
else
{
new_window.focus();
return false;
}
}

Code end
========
 
A

ASM

Markus said:
The new code is at the end of this posting

==========
Code start

var new_window = null;
var url = null;
function popup(element, width, height)
{
if (new_window == null || new_window.closed )

// you must firstable close the popup if it is open

if (new_window != null || !new_window.closed)
new_window.close();
else
{
if (element.getAttribute)

if (element.getAttribute && element.getAttribute('href'))
or (I prefer) :
if(element.href)
{
url = element.getAttribute('href');

url = element.href;
}
else
{
url = element;
}
new_window = window.open(url, 'tpc', 'width=' + width + ', height=' +
height + ', left=' + Math.round((screen.availWidth - width)/2) + ',
top=' + Math.round((screen.availHeight - height)/4) +
',scrollbars=1,resizable=yes');

Please : without space

new_window = window.open(url,'tpc','width=' + width +
',height=' + height +
',left=' + Math.round((screen.availWidth - width)/2) +
',top=' + Math.round((screen.availHeight - height)/4) +
',scrollbars=1,resizable=yes');
return false;

return false is of no use here
it has to be in the link :
onclick="popup(this,800,600); return false;"

Following is not a goog idea if the popup have to be set to new size
(if width and/or height are different from precedent call)
so delete it
 
G

Gérard Talbot

ASM wrote :
// you must firstable close the popup if it is open

if (new_window != null || !new_window.closed)
new_window.close();

This is not perfectly illogical. The window could be minimized or behind
the parent window (which is a situation which can happen often). In such
case, you'd need to focus back the requested popup window and do nothing
more, assuming that the same 3 parameters are the same. Here, the code
makes no distinction; it just closes an already existing window and then
recreates it entirely. The code you propose is not the best, the most
efficient.
else



if (element.getAttribute && element.getAttribute('href'))
or (I prefer) :
if(element.href)



url = element.href;



Please : without space

new_window = window.open(url,'tpc','width=' + width +
',height=' + height +
',left=' + Math.round((screen.availWidth - width)/2) +
',top=' + Math.round((screen.availHeight - height)/4) +
',scrollbars=1,resizable=yes');



return false is of no use here
it has to be in the link :
onclick="popup(this,800,600); return false;"



Following is not a goog idea if the popup have to be set to new size
(if width and/or height are different from precedent call)
so delete it

Yes, you're right and I understand what you mean... but what if it uses
the same values? The thing is that the code makes no distinction, is not
smart enough to deal with such cases. One way is to store the href
value, width and height values in 3 global variables and then to compare
in the function. It's a bit more complicated. If the webpage
requirements are there, then this would be justified code.

Gérard
 
A

ASM

Gérard Talbot said:
ASM wrote :

[snip]

(Following = something about popup focus)
Yes, you're right and I understand what you mean... but what if it uses
the same values?

I have to considere uses can be different from call to call
If not, width and height parameters have no sens
(no utility in function calls)
The thing is that the code makes no distinction, is not
smart enough to deal with such cases. One way is to store the href
value, width and height values in 3 global variables

A so usual and simple popup would really need more JS work with global
variables ?
and then to compare
in the function. It's a bit more complicated. If the webpage
requirements are there, then this would be justified code.

I think popup focus in end of code would have to exist if there is a
possbility it allready does exists.
In this case a window resizing would before hapen in the function.
But it seems that some browsers don't resize windows ?
(in same way as others)

i.e

function pop(page,width,height) {
var margh = screen.availHeight? screen.availHeight : screen.height;
margh = (margh-height)/2-30;
var margl = screen.availWidth? screen.availWidth : screen.width;
margl = (margl-width)/2-10;
if(!(!truc) || !truc.closed) '';
else truc = window.open('','','resizable=1,scrollbars=1');
with(truc) {
location.href = page;
resizeTo(width,height);
moveTo(margl,margh);
focus();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top