0

My question might be weird but I really need to trigger an onclick() event when visiting a web page.

Here's my code: https://github.com/Kakise/Blog/blob/master/themes/cactus/layout/_partial/scripts.ejs#L66

var disqus_shortname = '<%= theme.disqus.shortname %>';
$(document).ready(function() {
    $('#disqus-load').on('click', function(){ 
    $.ajax({
        type: "GET",
        url: "//" + disqus_shortname + ".disqus.com/embed.js",
        dataType: "script",
        cache: true
    });
    $(this).fadeOut();
}); });

I'd like that when I visit this url with #disqus_thread in the end, it acts as if I clicked on the #disqus-load div and loads the comments.

Thank you

1
  • Why can't you generalize the code in the click handler into a common function and call it in document.ready and in other areas where it needs to be bound to events and pass disqus_shortname as a parameter? Commented May 13, 2018 at 15:52

2 Answers 2

1

if clicking div#disqus-load does it then you can trigger a click response through jQuery -

$("#disqus-load").trigger('click');
Sign up to request clarification or add additional context in comments.

Comments

0

If you wish to do something upon loading you could always do .onload a better on would be JQuery's trigger method :

$('some_obj').trigger('click')

What this will do is that immediately upon load it will automatically trigger the click function (requires JQuery)


Resources :


Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.