如何在“X”秒后进行jquery函数调用

时间:2022-05-05 08:32:50

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

我有一个jquery函数,我需要在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?

我想在iframe中打开一个weblink,打开它后我需要调用下面的函数。那我该怎么做?

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:

这是我在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:

实际上这是我所拥有的简单页面:

如何在“X”秒后进行jquery函数调用

And this is the message 如何在“X”秒后进行jquery函数调用

这就是信息

2 个解决方案

#1


85  

You can just use the normal setTimeout method in JavaScript.

您可以在JavaScript中使用常规的setTimeout方法。

ie...

即...

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

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

在您的示例中,您可能希望直接使用showStickySuccessToast。

#2


2  

If you could show the actual page, we, possibly, could help you better.

如果您可以显示实际页面,我们可能会更好地帮助您。

If you want to trigger the button only after the iframe is loaded, you might want to check if it has been loaded or use the iframe.onload:

如果只想在加载iframe后触发按钮,可能需要检查它是否已加载或使用iframe.onload:

<iframe .... onload='buttonWhatever(); '></iframe>


<script type="text/javascript">

    function buttonWhatever() {
        $("#<%=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>

#1


85  

You can just use the normal setTimeout method in JavaScript.

您可以在JavaScript中使用常规的setTimeout方法。

ie...

即...

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

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

在您的示例中,您可能希望直接使用showStickySuccessToast。

#2


2  

If you could show the actual page, we, possibly, could help you better.

如果您可以显示实际页面,我们可能会更好地帮助您。

If you want to trigger the button only after the iframe is loaded, you might want to check if it has been loaded or use the iframe.onload:

如果只想在加载iframe后触发按钮,可能需要检查它是否已加载或使用iframe.onload:

<iframe .... onload='buttonWhatever(); '></iframe>


<script type="text/javascript">

    function buttonWhatever() {
        $("#<%=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>