SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Launch Additional Popups from the First Popup?

    I'd like to learn how to make a popup window, launched from a button, that allows additional instances of itself to be launched from the resulting popup. here's what I have so far:

    In the head:

    <script type="text/javascript">
    <!--
    function MyPopup() {
    window.open( "http://www.mysite.com/", "myWindow",
    "status=0, height=300, width=300, resizable=0, scrollbars=0, location=0, menubar=0" )
    }
    //-->
    </script>

    In the body:

    <input type="button" onClick="MyPopup()" value="Launch Another Window">

    This code is on the page that launches the popup the first time, and also the resulting popup. When I click the "Launch Another Window" from the popup, though, it just reloads inside itself and clicking the first button does the same thing (keeps "refreshing" the already launched popup). Any thoughts?

  2. #2
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    You'll have to give each pop-up its own name.

    Right now everything is loading inside that one window named, "myWindow". Perhaps one of the variables passed to the function can be a unique name.


    Code JavaScript:
    onclick="MyPopup('http://address','FirstWindow');"
    onclick="MyPopup('http://address','SecondWindow');"

    Code JavaScript:
    function MyPopup(windowAddress,windowName)
    	{
    	window.open(windowAddress,windowName,'etc.');
    	}




    _
    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  3. #3
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Hold up... why are you trying to launch multiple popup's here, they are a bad idea when you try to have just one but spamming multiple popup's is an accessibility and usability nightmare and I can gaurantee whoever does not have their popup blocker turned on by default will exit your website quicker than you can say Alt + F4.

  4. #4
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the popup isn't for advertising/spam it's a user launched window where I'd like to allow them the option of opening a few more instances of it if they choose. If it's possible, a way to limit how many could be open at one time would be good but I'm not sure it's within the scope of javascript (?).

  5. #5
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    It is.

    You'd just need a variable to keep count of how many windows are open.


    I know what Alex is trying to say, and he has a point, but I think Alex needs to remember that we all need to start somewhere and pop-up windows are a good intro into Javascript in my opinion.

    As a safety against pop-up blockers, don't forget to offer a regular href in your link, so that if the pop-window fails, the browser will at least follow through to the viewer's chosen web-page.

    The whole link will look something like this...


    Code JavaScript:
    <a href="http://address/" onclick="MyPopup('http://address/','Window','whatever'; return false;)" />

    The 'return false' part is important as it's what will prevent the browser from following the link if the pop-window does open successfully.

    ALSO... it's a good idea to offer some type of graphic or notice to your viewers that clicking the link will open the file in a new window. You can put a little pop-up icon next to the links for example.

    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  6. #6
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Shaun(OfTheDead) View Post
    I know what Alex is trying to say, and he has a point, but I think Alex needs to remember that we all need to start somewhere and pop-up windows are a good intro into Javascript in my opinion.
    I would say that perhaps alert("Hello world!"); would be the best starting point


Bookmarks

Posting Permissions

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