positioning a popup

Discussion in 'HTML' started by johnney, Aug 1, 2003.

  1. johnney

    johnney Guest

    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
     
    johnney, Aug 1, 2003
    #1
    1. Advertisements

  2. johnney

    Steve Pugh Guest

    This is okay as a learning exercise but please don't use this on a
    real web site.
    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
     
    Steve Pugh, Aug 1, 2003
    #2
    1. Advertisements

  3. johnney

    johnney Guest

    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?
     
    johnney, Aug 1, 2003
    #3
  4. johnney

    Steve Pugh Guest

    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.
    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
     
    Steve Pugh, Aug 1, 2003
    #4
  5. That's a hell of a typing error! I hope you don't work in a bank. If you do,
    I hope it isn't my bank! ;-)

    Cheers,
    Nige

    --
    Nigel Moss.

    Email address is not valid. . Take the dog out!
    http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
    "How strange the change from major to minor..."
     
    nice.guy.nige, Aug 1, 2003
    #5
  6. johnney

    johnney Guest



    Hello
    This is a bit off topic but is top posting a violation of newsgroup
    etiquette or something and if so
    why??
     
    johnney, Aug 1, 2003
    #6
  7. johnney

    brucie Guest

    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
     
    brucie, Aug 1, 2003
    #7
  8. johnney

    Sid Ismail Guest

    Sid Ismail, Aug 1, 2003
    #8
  9. johnney

    johnney Guest

    johnney, Aug 1, 2003
    #9
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.