View Full Version : Null reference error in javascript function?

04-30-2012, 10:03 AM
İ 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

<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;


if (readCookie('OnerFacebook') != 1) {
tb_show('', 'http://www.mobilyala.com/OnerFacebook/?KeepThis=true&TB_iframe=true&height=500&width=300&modal=true', '');


What should I do for it?

04-30-2012, 04:20 PM
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.