0

why my code is not working? I have called a javascript function after page load PHP script.like below:

<script>
setTimeout("fb_login()",100);
</script>

fb_login() function is on same page

function fb_login()
{
alert("ok");
}

Tried with setTimeout("fb_login",100); too. but not working.

I have checked console, but it's giving no error.

  • Did you try it with exactly `setTimeout("fb_login",100);`, i.e. with the double quotes around `fb_login` OR `setTimeout(fb_login,100);`? – jabclab Feb 08 '12 at 17:30

5 Answers5

2

Change this code:

<script>
    setTimeout("fb_login()",100);
</script>

to this:

<script>
    setTimeout(fb_login,100);
</script>

Good explanation from similar post - How can I pass a parameter to a setTimeout() callback?

Community
  • 1
  • 1
Alex
  • 34,899
  • 5
  • 77
  • 90
2

Just change it to:

<script>
    setTimeout(fb_login, 100);
</script>
jabclab
  • 14,786
  • 5
  • 54
  • 51
1

It might be you given less time in setTimeout but and it's calling your function befor page loaded fully. So Try to increase time.

<script>
setTimeout("fb_login()",1000);
</script>
1

Make sure that fb_login is being initialized before calling otherwise it will give error. Either use document.ready or add that function before it is called. Does it give you some error like "fb_login is undefined" ?

emphaticsunshine
  • 3,725
  • 5
  • 32
  • 42
0

try this

<script>
window.onload = function(){
   setTimeout(fb_login,100);
};

function fb_login(){
   alert("ok");
}

</script>

EDIT: first check if the below is working or not, if it does not work then pbm is somewhere else

window.onload = function(){
   setTimeout(function(){
     fb_login();
},100);
};
dku.rajkumar
  • 18,414
  • 7
  • 41
  • 58