Results 1 to 12 of 12
  1. #1
    Star Lounger
    Join Date
    Feb 2001
    Location
    Edinburgh, Scotland, United Kingdom
    Posts
    57
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Create a pop up window?

    I'm embarrassed to ask, but couldn't find reference to it anywhere here, so here goes...

    Can anyone give some code to create a pop-up window on loading a page (say index.html) with a pre-set size. That's the first part. The next bit is whether it's possible to have it only open if the person hasn't seen it before, or has clicked "Don't show me again". I guess this'll need cookies somehow?

    If the answers way too complicated for you to bother, any reference sites would be great instead.

    Thanks

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create a pop up window?

    Try this (it works for IE5 anyway):<pre><HTML>
    <BODY>


    <table border=0 bgcolor=#FFFF99 cellspacing=0 width=110 id="Hint"
    style='border:.5pt solid windowtext;position:absolute;top:-500'
    >
    <tr><td style="font:8pt">This is the text of what you want in the hint</td><tr>
    </table>

    <script>

    // If the cookie does not contain the string "Hinted", move the top of the Hint table
    if (document.cookie.indexOf("Hinted")== -1) {
    Hint.style.top = 100
    }

    expireDate = new Date
    expireDate.setMonth(expireDate.getMonth()+6)

    SetCookie ("Hinted",true,expireDate,"/")

    function SetCookie (name,value,expires) {
    document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "")
    }

    </script>
    </BODY>
    </HTML></pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Star Lounger
    Join Date
    Feb 2001
    Location
    Edinburgh, Scotland, United Kingdom
    Posts
    57
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Create a pop up window?

    Thanks very much Geoff. Does this HTML goes onto the pop up page or does it create a table on the index page?

    I know it's just one line, but I can't find the HTML to create a sized popup window.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create a pop up window?

    Colin,

    The bit I posted was a whole page (such as it was). It could stand alone as a basic page (it was just to give an idea) or to be incorporated into another page.

    So, to incorprate this into another page, you would need to do something like this:

    The bit between the "<table> and/table> tags is a very simple table, one row by one column. It's been specified as a table just to make it slightly easier to set up. So, to explain:<pre><table border=0 bgcolor=#FFFF99 cellspacing=0 width=110 id="Hint"
    style='border:.5pt solid
    position:absolute;top:-500' ></pre>

    Set up a table, with background colour = yellow. No cellspacing, 110 pixels wide, with a thin border. Position it 500 pixels above the current screen so it's not normably viewable. Give it an ID of "Hinted" so it can be referenced later.

    That chunk of HTML can be stuck on your page anywhere.

    The other bit is a Javascript which checks the cookie. <pre>if (document.cookie.indexOf("Hinted")== -1) { Hint.style.top = 100}</pre>

    checks the stored cookie. If the cookie DOES NOT contain the string "Hinted", set the style of the table set up previously (with the id "Hint") so that the top is now 10 pixels instead of -500 (you might have to play around with these values for the cookie to be positioned properly. So that little table ONLY gets shown if the cookie has not been set before.

    When you get used to it, you can place elements in relation to other elments- eg "Hint.style.top = Something.style.top" etc.

    The other bit (in the script tags):<pre>expireDate = new Date</pre>

    set up a new date variable<pre>expireDate.setMonth(expireDate.getMon th()+6)</pre>

    add 6 months to the cookie expiry date<pre>SetCookie ("Hinted",true,expireDate,"/")
    function SetCookie (name,value,expires) {
    document.cookie = name + "=" + escape (value) + ((expires) ? ";
    expires=" + expires.toGMTString() : "")
    }</pre>

    Set up a new cookie, with value "Hinted = true", to expire in 6 months. Sorry, the argument "/" was superfluous.

    Does that help at all?

    You were just talking HTML, I'm talking Javascript- but if you're talking cookies, or even popups, you need to understand some Javascript.

    I found the Wrox book on beginning Javascript a very good guide (sorry, I don't have the book name with me). <A target="_blank" HREF=http://www.w3schools.com/>http://www.w3schools.com/</A> has some good resources for learning javascript, dynamic HTML, and the like.

    There's some great things you can do- if you are doing any web developing at all, I certainly would encourage you to learn more. It's fun.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create a pop up window?

    To add an explanation to Colin.

    Jefferson's code shows how to open a new window- which is really what Colin asked in the original post. The code I posted opens a box within the current window. It's not a new window- just something which simulates the "hint" used in Office.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  6. #6
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles, California, USA
    Posts
    1,734
    Thanks
    0
    Thanked 3 Times in 1 Post

    Re: Create a pop up window?

    Because yours is DHTML, it may also not be cross-browser friendly.
    <IMG SRC=http://www.wopr.com/w3tuserpics/Eileen_sig.gif>

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Create a pop up window?

    What happened to my <A HREF= lines? They got converted to [url= tags.

    Well, use "java script:[i]scriptname[/i]" as the HREF for the tag and all should be well.

  8. #8
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create a pop up window?

    That's a fair point. I have the luxury of developing for an Intranet, where every browser is IE5.5.

    I've trended not to use pop-up windows, because I've found that if the user swaps back to the original window rather than closing the new window, then the next time the Javascript attempts to open the window, the user sees nothing happening. There's probably an answer to that- I didn't have the time to investigate further when that happened.

    Another way of displaying a message to a user is by using "alert". I don't think there will be any cross-browser issues there.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Create a pop up window?

    To control the size of a new window you do have to use JavaScript, and not just the target tag.

    Example #1: The nonscrollable 1-Click TagPanel windows opens with this code:

    In the <SCRIPT> tab:

    <pre> function popTags() {
    var w = open("http://www.wopr.com/cgi-bin/w3t/tagpanel2.pl","popTags",<font color=red>

  10. #10
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles, California, USA
    Posts
    1,734
    Thanks
    0
    Thanked 3 Times in 1 Post

    Re: Create a pop up window?

    That shouldn't happen - I'll check the filter.
    I've edited your post to make it show them properly...
    <IMG SRC=http://www.wopr.com/w3tuserpics/Eileen_sig.gif>

  11. #11
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create a pop up window?

    Jefferson,

    A very minor point.

    I do like your use of the red dash to split a line. It would be useful for some of the Excel formulae which pop up from time to time.

    But I don't think it's absolutely necessary in this case. I think Javascript (at least the IE dialect) allows you to split the parameters across lines.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  12. #12
    Star Lounger
    Join Date
    Feb 2001
    Location
    Edinburgh, Scotland, United Kingdom
    Posts
    57
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Create a pop up window?

    Thanks to everyone for your suggestions. I'm going to try a number to see which works best. Amazing what interest this has created! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •