By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

dynamic popup

P: n/a
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','des','499',' 610','desert.jpg','desert')">b1</a>
<a
href="javascript:openPop('popup.htm','tus','330',' 630','cactus.jpg','cactus')">b2</a>
Jul 23 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
playmaker wrote:
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','des','499',' 610','desert.jpg','desert')">b1</a> <a

href="javascript:openPop('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:opener.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.

Jul 23 '05 #2

P: n/a
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:openPop("+"'"+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

Jul 23 '05 #3

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

PM
Jul 23 '05 #4

P: n/a
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.

Jul 23 '05 #5

P: n/a
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

Jul 23 '05 #6

P: n/a
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.

Jul 23 '05 #7

P: n/a
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
Jul 23 '05 #8

P: n/a
playmaker wrote:
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.

Jul 23 '05 #9

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

PM

RobB wrote:
playmaker wrote:
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.

Jul 23 '05 #10

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

PM

RobB wrote:
playmaker wrote:
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.


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:opener.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.

Jul 23 '05 #11

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

PM

RobB wrote:
playmaker wrote:
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


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

PM


correct.

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:opener.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.

Jul 23 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.