Reputation:
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
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
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
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
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