dynamic popup

P

playmaker

Hi,
I have two buttons calling the same funtion to open a popup window,
dinamically built according to parameters passed to the function.

The problem: when I click the first button (or the second), anything
goes. When I call the function again /that is, from the athor button), I
get no window subtitution: that is, the second popup loads into the
first, loosing w and h too...

I simply need this substitution: is this possible?

Thanks to everybody in advance, PM



---

<script>
function openPop(url, nome, w, h, pD, tD) {
var features = "";
features += "scrollbars=no,";
features += "menubar=no,";
features += "resizable=no,";
features += "left="+Math.floor(screen.width/2-w/2)+",";
features += "top="+Math.floor(screen.height/2-h/2)+",";
features += "alwaysRaised=yes,";
features += "width=" + w + ",";
features += "height=" + h;
nw = window.open(url, nome, features);
nw.document.open();
nw.document.write("<html>");
nw.document.write("<head>");
nw.document.write("<title>"+tD+"</title>");
nw.document.write("</head>");
nw.document.write("<body leftmargin='0' topmargin='0' marginwidth='0'
marginheight='0'>");
nw.document.write("<img src="+pD+" width="+w+" height="+h+" title="+tD+">");
nw.document.write("</body>");
nw.document.write("</html>");
nw.document.close()
}

</script>


<a
href="javascript:eek:penPop('popup.htm','des','499','610','desert.jpg','desert')">b1</a>
<a
href="javascript:eek:penPop('popup.htm','tus','330','630','cactus.jpg','cactus')">b2</a>
 
R

RobB

playmaker said:
Hi,
I have two buttons calling the same funtion to open a popup window,
dinamically built according to parameters passed to the function.

The problem: when I click the first button (or the second), anything
goes. When I call the function again /that is, from the athor button), I
get no window subtitution: that is, the second popup loads into the
first, loosing w and h too...

I simply need this substitution: is this possible?

Thanks to everybody in advance, PM



---

<script>
function openPop(url, nome, w, h, pD, tD) {
var features = "";
features += "scrollbars=no,";
features += "menubar=no,";
features += "resizable=no,";
features += "left="+Math.floor(screen.width/2-w/2)+",";
features += "top="+Math.floor(screen.height/2-h/2)+",";
features += "alwaysRaised=yes,";
features += "width=" + w + ",";
features += "height=" + h;
nw = window.open(url, nome, features);
nw.document.open();
nw.document.write("<html>");
nw.document.write("<head>");
nw.document.write("<title>"+tD+"</title>");
nw.document.write("</head>");
nw.document.write("<body leftmargin='0' topmargin='0' marginwidth='0'
marginheight='0'>");
nw.document.write("<img src="+pD+" width="+w+" height="+h+" title="+tD+">");
nw.document.write("</body>");
nw.document.write("</html>");
nw.document.close()
}

</script>


<a
href="javascript:openPop('popup.htm' said:
href="javascript:eek:penPop('popup.htm','tus','330','630','cactus.jpg','cactus')">b2</a>

Not precisely sure what the problem is - the usual culprit is use of
the same name for both windows, but you didn't do that. In any event,
that script has whiskers on it, along with some oddities
('alwaysRaised' only works with signed scripts, e.g.), and the code is
about as inefficient as possible. Nothing for the JS-disabled either.
Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript">

function openPop(pD, nome, w, h, tD)
{
var features = [
'scrollbars=no' ,
'menubar=no' ,
'resizable=no' ,
'left='+Math.floor(screen.width/2-w/2) ,
'top='+Math.floor(screen.height/2-h/2) ,
'width=' + w,
'height=' + h
].join(',');
HTML = [
'<html>' ,
'<head>' ,
'<title>'+tD+'</title>' ,
'</head>' ,
'<body style="margin:0;">' ,
'<img src="'+pD+'" width="'+w+'" height="'+h+'" title="'+tD+'">' ,
'</body>' ,
'</html>'
].join('');
nw = window.open('javascript:eek:pener.HTML', nome, features);
if (nw && !nw.closed && nw.focus)
nw.focus();
return false;
}

</script>
</head>
<body>
<a href="desert.jpg" onclick="return
openPop(this.href,'des','499','610','desert')">b1</a>
<a href="cactus.jpg" onclick="return
openPop(this.href,'tus','330','630','cactus')">b2</a>
</body>
</html>

Don't use pop-ups, blah blah blah...I'll spare you the lecture.
 
P

playmaker

Hi,
first of all thanks.

Second: I'm sorry for the oddities but it is my first js function ever,
so excuse me...

And... I gave you the code to call a function from html but I forgot to
say that I'm calling the function from Flash this way:

on (release) {
u = "popup.htm";
n = 'nnn';
ww = 450;
hh = 560;
img = 'cactus.jpg';
tt = 'Titletitle';

getURL("javascript:eek:penPop("+"'"+u+"'"+','+"'"+n+"'"+','+"'"+ww+"'"+','+"'"+hh+"'"+','+"'"+img+"'"+','+"'"+tt+"'"+")");
}

I receive the values of those vars (u, n, ww etc.) from PHP/MySQL and I
use them to open popups. Why popups? Simple: it is the site of a visual
artist (a painter) and the substance of the site is his work (I put 10
thumbnails for page and I click on them to open the popups). The idea of
using one single popup is to avoid that one user opens 10 popup at the
same time... So I had to "mediate" a solution...

Thanks for the cose, now I must understand how use it from the swf file.

best regards,
PM
 
P

playmaker

Hi,
I tryed you code "as is" (without Flash)
but is doesn't work (IE 6, Firefox 1)... I can't understand why...

PM
 
R

RobB

If there's a line break after 'return' (in the link),
remove it.

Should be easy enough to modify...no need to pass a url, since you're
just generating a new document anyway; the only url you need is
that of the pic. I prefer loading a window with a favelet (javascript:)
over
the usual document.writes. (Much) less likely to encounter timing
problems
that way.

Take a look at some of the slide shows at

http://slayeroffice.com/index.php

Imaginative, and done within the same window, avoiding blocker problems

and the like.
 
P

playmaker

everything is very beautyful there... :)

Anyway, the code (don't know why) it is not working:
it opens a page as it was open using "_blank" and display the image in
the page: every toolbar is there, so any other attrubute... It IS a new
page, not a popup and I can't see the source ("html" is grayed)...

Thanks, PM
 
R

RobB

This must be on one line:

<a href="desert.jpg" onclick="return
openPop(this.href,'des','499','610','desert')">b1</a>

Remove any carriage returns.
 
P

playmaker

fantastic...
Only one thing: on IE6 I get a little white space under the image (3 or
4 pixel): is there any way to eliminate it?

Thanks, PM
 
R

RobB

playmaker said:
fantastic...
Only one thing: on IE6 I get a little white space under the image (3 or
4 pixel): is there any way to eliminate it?

Thanks, PM

Try modifying these lines:

'<body style="margin:0;background:black;">' ,
'<img src="'+pD+'" width="'+w+'" height="'+h+'" title="'+tD+'"
border="0">' ,

(each one on ONE line only)...make sure you've got the image dimensions
correct.
 
P

playmaker

Hi, I tried but it's the same:
the features are correct (w and h):
the problem is only for IE6/XP/SP2... :-(

PM
 
R

RobB

playmaker said:
Hi, I tried but it's the same:
the features are correct (w and h):
the problem is only for IE6/XP/SP2... :-(

PM

Looks OK here. Try substituting:

...............
...............
HTML = [
'<html>' ,
'<head>' ,
'<title>'+tD+'</title>' ,
'</head>' ,
'<body style="margin:0;background:black;">' ,
'<img style="border-width:0;" src="'+pD+'" title="'+tD+'">' ,
'</body>' ,
'</html>'
].join('');
nw = window.open('javascript:eek:pener.HTML', nome, features);
if (nw && !nw.closed && nw.focus)
nw.focus();
return false;
}

Make sure the image size is accurate. Images will resize in the browser
if the dimensions are set in HTML/CSS so, don't trust those properties.
Open the image (url) in its own window, or in your image editor.
 
P

playmaker

RobB said:
dimensions

I tryed anything:
anything goes if I resizeBy(0,-3)...

PM




Looks OK here. Try substituting:

..............
..............
HTML = [
'<html>' ,
'<head>' ,
'<title>'+tD+'</title>' ,
'</head>' ,
'<body style="margin:0;background:black;">' ,
'<img style="border-width:0;" src="'+pD+'" title="'+tD+'">' ,
'</body>' ,
'</html>'
].join('');
nw = window.open('javascript:eek:pener.HTML', nome, features);
if (nw && !nw.closed && nw.focus)
nw.focus();
return false;
}

Make sure the image size is accurate. Images will resize in the browser
if the dimensions are set in HTML/CSS so, don't trust those properties.
Open the image (url) in its own window, or in your image editor.
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top