Results 1 to 2 of 2

Thread: Null reference error in javascript function?

  1. #1
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Null reference error in javascript function?

    İ want to use this code but when the page opens, I get a null reference error. When I open the page a second time, this error doesn't occur.

    I understand when the site caches, this error doesn't occur. The error comes from tb_show function.

    i try everything and im goint to be a mad man

    Code:
     <script type="text/javascript"> 
    
    function writeCookie(CookieAdi) { 
    var dtGun = 1 
    var strValue = "1" 
    if (dtGun == null || dtGun == "") dtGun = 365; 
    var d = new Date(); 
    d.setTime(d.getTime() + (dtGun * 24 * 60 * 60 * 1000)); 
    var zt = "; expires=" + d.toGMTString(); 
    document.cookie = CookieAdi + "=" + strValue + zt + "; path=/"; 
    } 
    
    function readCookie(cookieadi) { 
    var c = document.cookie; 
    if (c.indexOf(cookieadi) != -1) { 
    s1 = c.indexOf("=", c.indexOf(cookieadi)) + 1; 
    s2 = c.indexOf(";", s1); 
    if (s2 == -1) s2 = c.length; 
    strValue = c.substring(s1, s2); 
    return strValue; 
    } 
    } 
    
    
    writeCookie('OnerFacebook'); 
    
    
    if (readCookie('OnerFacebook') != 1) { 
    tb_show('', 'http://www.mobilyala.com/OnerFacebook/?KeepThis=true&TB_iframe=true&height=500&width=300&modal=true', ''); 
    } 
    
    
    </script>
    What should I do for it?
    Last edited by jscheuer1; 04-30-2012 at 04:03 PM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    In the code in your post, tb_show is not defined, but that doesn't matter because it's only fired if the cookie isn't set and the cookie is set before that. Perhaps some browsers are slow to set the cookie the first time. I tested in IE 9 and Firefox 12. Both were quick enough that they never tried to fire tb_show, so there was no error.

    So either that (slow browser), or the code in your post isn't quite exactly the code that's on your problem page, and/or there's also other code that's causing the problem. Perhaps it's something else. Hard to say without seeing the page.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •