user1119566
user1119566

Reputation:

javascript function not working after page load

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.

Upvotes: 0

Views: 497

Answers (5)

emphaticsunshine
emphaticsunshine

Reputation: 3765

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" ?

Upvotes: 1

dku.rajkumar
dku.rajkumar

Reputation: 18568

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

Upvotes: 0

Alex
Alex

Reputation: 35409

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?

Upvotes: 2

user319198
user319198

Reputation:

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>

Upvotes: 1

jabclab
jabclab

Reputation: 15042

Just change it to:

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

Upvotes: 2

Related Questions