SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot Matt_M's Avatar
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Any way to stop this pop under from being blocked?

    Hi,

    I am using this code:

    Code:
    <script>
    
    var popunder="http://www.yahoo.com"
    
    //specify popunder window features
    //set 1 to enable a particular feature, 0 to disable
    var winfeatures="width=780,height=500,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0"
    
    //Pop-under only once per browser session? (0=no, 1=yes)
    //Specifying 0 will cause popunder to load every time page is loaded
    var once_per_session=1
    
    ///No editing beyond here required/////
    
    function get_cookie(Name) {
      var search = Name + "="
      var returnvalue = "";
      if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
          offset += search.length
          // set index of beginning of value
          end = document.cookie.indexOf(";", offset);
          // set index of end of cookie value
          if (end == -1)
             end = document.cookie.length;
          returnvalue=unescape(document.cookie.substring(offset, end))
          }
       }
      return returnvalue;
    }
    
    function loadornot(){
    if (get_cookie('popunder')==''){
    loadpopunder()
    document.cookie="popunder=yes"
    }
    }
    
    function loadpopunder(){
    win2=window.open(popunder,"",winfeatures)
    win2.blur()
    window.focus()
    }
    
    if (once_per_session==0)
    loadpopunder()
    else
    loadornot()
    
    </script>
    But Internet Explorer is blocking it. Is there any way to modify this code to stop it from being blocked?

    Thanks, Matt

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,999
    Mentioned
    186 Post(s)
    Tagged
    2 Thread(s)

    pop-up pop-under

    Unfortunately too many sites have abused pop-ups (too many per visit, can't be resized/closed, etc). So now pop-up blockers are very popular. However, most blockers will allow new windows to open when the action is initiated not by script, but by user action. If you have your pop-under available as a link IE should allow it.

  3. #3
    SitePoint Zealot Matt_M's Avatar
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm... is there something that I can add to this code that says that if any of the links on my site are clicked, then pop? It would still only have to pop once per session though.

    Thanks, Matt

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Add the following two lines in bold and clicking anywhere in the page should trigger it once.

    Code:
    window.onclick = function() {
    if (once_per_session==0)
    loadpopunder();
    else
    loadornot();
    }
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Zealot Matt_M's Avatar
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help, but I tried adding those lines and it did not try to pop at all, whether I tried to click or not.

  6. #6
    SitePoint Zealot Matt_M's Avatar
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone else?

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The only way to ensure a popup will get past most blockers is to code it as <a onclick="window.open()">. Most blockers will allow that but many will block any popup where the window.open is not actually inside an <a> tag while others will allow it as long as the code is in a function called from an <a> tag.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    i ahev a question for this

    i donot need the popunder happen all the time
    so this code will NOT let opunder happen all the time,right?
    i just need one time per day!
    waiting for reply

  9. #9
    SitePoint Zealot Matt_M's Avatar
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code that I posted triggers a popunder once per session.

  10. #10
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks ,i will try it

    i will try it!


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
  •