I have a large form that is often used but takes 2-3 seconds to load. To get around this, I have it loaded by clicking the <a id="doc_ready_link" class="use-ajax" link with JS on page load.
document.querySelector('#doc_ready_link').click(); Module
function custom_ajax_page_st_form_menu() { $items['class-content-form'] = array( 'page callback' => 'ajax_content_response', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } On faster machines like my laptop or phone, this is fine and I have a fast page load and a spinner on the form link.
But on slower laptops and phones, other JS stuff like the menu doesn't work until it's loaded giving a bad UX.
How do I get that form loaded with ajax after page load without locking up the browser? For a normal click, the UX is ok but when it's all hidden like what I'm doing, the clunkiness is jarring.
Thanks.
EDIT:
I have tried the other methods below for clicking the link but the locking of other JS remains on slower devices. I'm still looking for some other method, most likely a snippet of $.ajax code that can call my module's code just like class="use-ajax" does.
PS for anyone wondering how to click Flags etc. in Drupal:
document.querySelector('#').click(); works when $('#').click(); usually doesn't.
Edit: For what it's worth, this is the module that the "use-ajax" link calls but I don't think it matters much.
<?php function custom_ajax_page_st_form_form_init() { drupal_add_js('misc/jquery.form.js'); drupal_add_library('system', 'drupal.ajax'); } /** * Implements hook_menu(). */ function custom_ajax_page_st_form_menu() { // A menu callback is required when using ajax outside of the Form API. $items['class-content-form'] = array( 'page callback' => 'ajax_content_response', // 'access callback' => 'user_access', 'access arguments' => array( 'access content' ), 'type' => MENU_CALLBACK ); return $items; } function ajax_content_response($type = 'ajax', $nid = 0, $node_type = "", $home_nid) { $output = _custom_page_st_form_loader(); if ($type == 'ajax') { $commands = array(); $commands[] = ajax_command_replace('#class_form_load', '<div id="class_form_load">' . $output . '</div>'); // $commands[] = ajax_command_invoke('.add_menu', 'show'); // Remove Spinner $commands[] = ajax_command_invoke('html', 'trigger', array( 'remove_ajax_spinner' )); // Set Groups Audience if ($nid != 0) { $commands[] = ajax_command_invoke('#edit-og-group-ref-und-0-default', 'val', array( $nid )); $commands[] = ajax_command_invoke('#edit-og-group-ref-und-0-default', 'trigger', array( "chosen:updated" )); } // Set Home if ($nid != 0) { if ($node_type == "homepage_group") { $commands[] = ajax_command_invoke('.form-item-field-home-und input', 'prop', array( "checked", true )); } // $(".form-item-field-home-und input").prop("checked", true) } // Set Homepage Audience $commands[] = ajax_command_invoke('#edit-field-homepage-audience-und-0-default', 'val', array( $home_nid )); $commands[] = ajax_command_invoke('#edit-field-homepage-audience-und-0-default', 'trigger', array( "chosen:updated" )); $page = array( '#type' => 'ajax', '#commands' => $commands ); ajax_deliver($page); } else { $output = '<div id="class_form_load">' . $output . '</div>'; return $output; } } function _custom_page_st_form_loader() { module_load_include('inc', 'node', 'node.pages'); $form = node_add('class_content'); return drupal_render($form); } And the reason this is a big deal for my site. There are 8 JS buttons that users click very quickly on the site and all break on slow devices.

$.ajax. It's also more generic which is good for SE. My original question wasHow to replace a "use-ajax" link that's auto-clicked on page load?. I thought I made it clear that I wanted that functionality replaced and that I had a working solution very similar to the two provided. They still lock the browser on slower machines because they still use the "use-ajax" link I want replaced with something else.