positioning a popup

J

johnney

hi.
I'm very new to javascript so please be patient with me. I want to cause a
popup window to open, but in a random position on the screen. I've tried
this but it doesn't work:

<body onload="window.open('hello.htm', 'newWindow',
'scrollbars=0,resizable=0,height=30,width=30,left=xaxis,top=300')">
<SCRIPT LANGUAGE="JavaScript">
var xaxis= Math.round(Math.random()*4);
</script>

does anyone know why the positioning values can't be variables. When i
substitute a variable for the height or width it works okay, but when i use
one for the left or top value it is ignored?
Any help would be appreciated
 
S

Steve Pugh

johnney said:
I'm very new to javascript so please be patient with me. I want to cause a
popup window to open, but in a random position on the screen.

This is okay as a learning exercise but please don't use this on a
real web site.
I've tried this but it doesn't work:

<body onload="window.open('hello.htm', 'newWindow',
'scrollbars=0,resizable=0,height=30,width=30,left=xaxis,top=300')">
<SCRIPT LANGUAGE="JavaScript">
var xaxis= Math.round(Math.random()*4);
</script>

Two obvious errors.
1. You're giving left the value as literally xaxis, not as teh
variable xaxis.

You need
onload="window.open('hello.htm', 'newWindow',
'scrollbars=0,resizable=0,height=30,width=30,left=' + xaxis +
',top=300')"

2. Now it works but the random number will be between 0 and 4. No
on'es going to notice the difference. Instead of 4 use a larger
multiplier.

You do realise that this will be really annoying? Imagine having a
small window popping up in a random location every time you visit the
page. It might be marginally interesting for some people the first
time they visit, but what about on the second, third or tenth visit?

Many people use popup blockers (either built into browsers like
Mozilla and Opera, or as additional software) and windows that open
automatically from an onload event are the most likely to be blocked.
So don't put anything important into this window as many people just
won't see it (including a lot of people who'll get the popup and close
it without reading it).

Steve
 
J

johnney

Okay It works thanks

The 4 was a typing error is was meant to be 600 or 700
Putting the variable in the '+ signs works. But why is it okay to put xaxis
directly into the width or height attributes? and if i put
document.write(xaxis) it displays the numerical value not literally xaxis?
I know popups are really annoying so i won't be using it on any site.
Does anyone know what percentage of people have popup blockers?. If it's
high do you think were in the final days of them?
 
S

Steve Pugh

johnney said:
Okay It works thanks

You're welcome, but please don't top post.
But why is it okay to put xaxis
directly into the width or height attributes?

I have no idea, it shouldn't work for the same reason that setting the
value of left didn't work.
and if i put
document.write(xaxis) it displays the numerical value not literally xaxis?

Yes, but that's not the same.
If wanted to put "The number is 444" into the page where 444 was
xaxis you would need to use
document.write('The number is' + xaxis)

The windowFeatures parameter of the window.open method is a string
contained within the quotes. If you want to include a variable as part
of that string you have the do the whole close quote + variable + open
quote business.
I know popups are really annoying so i won't be using it on any site.
Does anyone know what percentage of people have popup blockers?. If it's
high do you think were in the final days of them?

No idea about percentages. We can hope that popups are going to be
less of a blight than they have been but id oubt they'll vanish
entirely.

Steve
 
J

johnney

Steve Pugh said:
You're welcome, but please don't top post.


I have no idea, it shouldn't work for the same reason that setting the
value of left didn't work.
xaxis?

Yes, but that's not the same.
If wanted to put "The number is 444" into the page where 444 was
xaxis you would need to use
document.write('The number is' + xaxis)

The windowFeatures parameter of the window.open method is a string
contained within the quotes. If you want to include a variable as part
of that string you have the do the whole close quote + variable + open
quote business.


No idea about percentages. We can hope that popups are going to be
less of a blight than they have been but id oubt they'll vanish
entirely.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <[email protected]> <http://steve.pugh.net/>



Hello
This is a bit off topic but is top posting a violation of newsgroup
etiquette or something and if so
why??
 
B

brucie

This is a bit off topic but is top posting a violation of newsgroup
etiquette or something and if so why??

How am I supposed to post my replies in a newsgroup?:
http://allmyfaqs.com/faq.pl?How_to_post

How do I quote correctly in Usenet? - Quoting and Answering
http://www.netmeister.org/news/learn2quote2.html

The advantages of Usenet's quoting conventions
http://homepage.ntlworld.com/g.mccaughan/g/remarks/uquote.html

Why is Bottom-posting better than Top-posting
http://www.caliburn.nl/topposting.html

Rules for posting to Usenet
http://www.faqs.org/faqs/usenet/posting-rules/part1/

Bottom vs. top posting and quotation style on Usenet
http://www.cs.tut.fi/~jkorpela/usenet/brox.html

What do you mean "my reply is upside-down" ?
http://www.i-hate-computers.demon.co.uk/

How do i use lookout express properly?
http://www.html-faq.com/faq.php?key=outlook

The power of negative thinking:
The seven don'ts of Usenet, or how to excel without doing anything
http://www.cs.tut.fi/~jkorpela/usenet/dont.html
 

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
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top