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

Kakise
  • 33
  • 3
  • 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? – Lasitha Petthawadu May 13 '18 at 15:52

2 Answers2

1

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

$("#disqus-load").trigger('click');
Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68
thephpx
  • 522
  • 4
  • 15
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 :


Muhammad Salman
  • 433
  • 6
  • 18