SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2002
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    "is not a function" error

    I have the following javascript in the body of a file:

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    
    // Select random number from 0 to 99 (100%)
    var num = Math.round(Math.random()*(99));
    
    // Select file based on generated number
    if( num < 50 ) {       //50%
    	document.write('<scr'+'ipt src="/ADIN/popunder200.js" language="JavaScript" type="text/javascript"></scr'+'ipt>');
    } else if( num < 85 ) {//35% (=85%-50%)
    	document.write('<scr'+'ipt src="/ADIN/popunder400.js" language="JavaScript" type="text/javascript"></scr'+'ipt>');
    } else {               //15% (=100%-85%)
    	document.write('<scr'+'ipt src="/ADIN/popunder600.js" language="JavaScript" type="text/javascript"></scr'+'ipt>');
    }
    
    -->
    </script>
    The code in the files it calls is the same in all three cases, with the exception of the size of the windows (hence the 200, 400, and 600 in the file name.) Here is the code for the popunder200.js file:

    Code:
    if (get_cookie('popunder')=='') {
    var popUnderWindow = window.open("http://www.domainname.com/cgi-bin/advertpro/banners.fpl?region=65&mode=POPUP&keyword=NULL", "popunder", "width=200,height=200");
    popUnderWindow.blur();
    document.cookie="popunder=yes";
    }
    
    function get_cookie(name) {
      var search = name + "=";
      var returnvalue = "";
      if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
          offset += search.length;
          end = document.cookie.indexOf(";", offset);
          if (end == -1) {
            end = document.cookie.length;
            returnvalue=unescape(document.cookie.substring(offset, end));
          }
        }
      }
      return returnvalue;
    }
    In Firefox, I am generating the following error:

    "popUnderWindow.blur is not a function
    Source File: http://www.domainname.com/ADIN/popunder200.js Line 3"

    ...which references the "popUnderWindow.blur();" line.

    I've been researching the internet all day on this and I am no closer to a solution. I don't know how to fix this error and I need help. Anyone have solutions?


    Thanks!

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is probably because firefox blocks your popup window. A good practice is always to check value returned from window.open (it is null if popup was blocked):

    Code:
    var popUnderWindow = window.open(...);
    if(!popUnderWindow)
        // popup is blocked
    else
       // popup is okay


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
  •