Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a jquery function call after "X" seconds

I have a jquery function and I need to call it after opening the website in an Iframe.

I am trying to open a weblink in an Iframe and after opening it I need to call the below function. So how do I do that?

Here is my function:

<script type="text/javascript">        $(document).ready(function(){            $("#<%=Button1.ClientID%>").click(function (event) {              $('#<%=TextBox1.ClientID%>').change(function () {                 $('#various3').attr('href', $(this).val());             });             $("#<%=Button2.ClientID%>").click();         });       })     function showStickySuccessToast() {         $().toastmessage('showToast', {             text: 'Finished Processing!',             sticky: false,             position: 'middle-center',             type: 'success',             closeText: '',             close: function () {              }         });     }      </script> 

This is my button to open the link in an IFrame:

<a id="various3" href="#"><asp:Button ID="Button1"  runat="server" Text="Button" OnClientClick="Button2_Click"/></a> 

Actually this is the simple Page I'm having:

enter image description here

And this is the message enter image description here

like image 501
coder Avatar asked Nov 21 '11 18:11

coder


People also ask

How do I call a function after 2 seconds in jQuery?

To call a jQuery function after a certain delay, use the siteTimeout() method. Here, jQuery fadeOut() function is called after some seconds.

Which method is used to call a function once after X seconds?

To execute the function only once, use the setTimeout() method instead.

How can we call a function automatically after waiting for some time in jQuery?

How to call a function automatically after waiting for some time using jQuery? In order to run a function automatically after waiting for some time, we are using the jQuery delay() method. The . delay() method in jQuery which is used to set a timer to delay the execution of the next item in the queue.


1 Answers

You can just use the normal setTimeout method in JavaScript.

ie...

setTimeout( function(){      // Do something after 1 second    }  , 1000 ); 

In your example, you might want to use showStickySuccessToast directly.

like image 174
Layke Avatar answered Oct 04 '22 03:10

Layke