You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在页面加载后禁用指定JavaScript函数20秒(WordPress场景)

Got it, here's a solid approach to temporarily disable your target function from leadclick.js for 20 seconds once the page finishes loading in your WordPress setup:

Step 1: Update Your PHP Script Enqueue Code

We'll add an inline script that runs right after leadclick.js loads. This script will override your target function with a "do nothing" version, then restore the original function after 20 seconds.

Modify your existing PHP code like this:

$LeAdClickonline = get_option('video-LeAdClick-online'); 
if ($LeAdClickonline === 'on') { 
    wp_enqueue_script( 
        'video_LeAdClick_localized', 
        plugin_dir_url(__FILE__) . '/js/leadclick.js', 
        array('jquery') 
    );

    // Inline script to handle the 20-second disable
    wp_add_inline_script(
        'video_LeAdClick_localized',
        '
        // Replace "yourTargetFunction" with the actual function name from leadclick.js
        const originalLeadClickFunction = window.yourTargetFunction;
        
        // Override the function to do nothing temporarily
        window.yourTargetFunction = function() {
            // Optional: Add a console log or user message here
            console.log("This function is disabled for 20 seconds.");
        };
        
        // Restore the original function after 20000ms (20 seconds)
        setTimeout(() => {
            window.yourTargetFunction = originalLeadClickFunction;
            console.log("Function is now active again.");
        }, 20000);
        ',
        'after' // Critical: Ensures this runs AFTER leadclick.js loads
    );
}

Key Things to Adjust:

  • Function Name: Replace yourTargetFunction with the exact name of the function in leadclick.js you want to disable. For example, if the function is called trackLeadClick, use window.trackLeadClick.
  • User Feedback: The console logs are optional—you can replace them with a frontend alert (like alert("Please wait 20 seconds before using this feature.")) if you want users to see a message.

Alternative: Edit leadclick.js Directly

If you'd rather modify the original script instead of adding inline code, wrap your function definition in a setTimeout inside leadclick.js:

// Inside leadclick.js
setTimeout(() => {
    // Your original function code here
    window.yourTargetFunction = function() {
        // All the original logic from the function
    };
}, 20000);

This way, the function won't exist until 20 seconds after the script loads, so it can't be called during that time.


内容的提问来源于stack exchange,提问作者user9860866

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:56:04