Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts

    stupid pop up blocker

    pop up blocker is stopping my user action from using window.open. It is a html button that i want to open a dialog to tell the user his item was added to the shopping cart. The sumbit_cart() function is supposed to send a request via ajax then use window.open to open the dialog if the ajax function was successful.

    Code:
    <input type="button" value="Add to Cart" onclick="return submit_cart();" />
    I can understand the pop up blocker from blocking random pop ups but this is a user triggered event i don't see why it isn't allowing it.

    What can i do to make this work?
    You can not say you know how to do something, until you can teach it to someone else.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,170
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Simple - don't use a popup. A modal dialog will in any case quickly bore and irritate your users. Show your message, for example, in a <span> with display:inline.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Maybe i will do that if i cant find a solution to using the pop up. I didn't want it to direct to another page but i guess i could try some sort of hidden element if not.
    You can not say you know how to do something, until you can teach it to someone else.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,695
    Thanks
    80
    Thanked 4,511 Times in 4,475 Posts
    Use a POPON instead of a popup.

    Like this, for example:

    Code:
    <html>
    <body>
    <div id="POPON" 
         style="position: absolute; top: 200px; left: 100px; height: 200px; width: 300px; 
                background-color: lightblue; border: solid blue 3px;display: none;">
        <div style+width: 100%; text-align: right;">
            <a href="#" onclick="document.getElementById('POPON').style.display='none';return false;">
                   click here to close
            </a>
        </div>
        <div id="POPMESSAGE" style="margin-top: 40px;text-align: center;color: blue;"></div>
    </div>
    ...
    <script type="text/javascript">
    function showPopon( msg )
    {
        document.getElement("POPMESSAGE").innerHTML = msg;
        document.getElement("POPON").style.display = "block";
    }
    </script>
    ...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    timgolding (03-23-2012)

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Thanks for the code ill give it a try

    Edit:
    Got it working it looks good thanks. Just got to see what my boss thinks of it now....
    Last edited by timgolding; 03-23-2012 at 12:20 PM.
    You can not say you know how to do something, until you can teach it to someone else.

  • #6
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by timgolding View Post
    I can understand the pop up blocker from blocking random pop ups but this is a user triggered event i don't see why it isn't allowing it.
    Users should, and do, have the final say in whether popups are allowed or not. Not the web developer. Just because a user clicks a button, doesn't mean they would have clicked the button if they knew doing so would open a popup. For critical things you can create and style your own html element on the page to make it look like a popup.

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,412
    Thanks
    11
    Thanked 595 Times in 575 Posts
    Quote Originally Posted by timgolding View Post
    I can understand the pop up blocker from blocking random pop ups but this is a user triggered event i don't see why it isn't allowing it.

    What can i do to make this work?
    look like folks are avoiding the question...

    it's not a user-triggered event. the ajax fetch is a user-triggered event.

    later on, the returning ajax callback invokes window.open().

    since this is after a user click, and the ajax event is async, the open() command is not on the same stack as a legit user click.

    you can open a window immediately in the click , then fill in the popup when the ajax completes (ala popupObject.document.body.innerHTML="done")
    this also gives you a space and method to report progress on long-running queries.
    Last edited by rnd me; 03-25-2012 at 08:15 AM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Tags for this Thread

    Posting Permissions

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