1

This question is based on this question; but, there are some differences.


My friend has an online webpage, which it has an inline script tag, there is a JavaScript function:

(#1):

var domain = window.location.protocol + "//" + window.location.host + '/';

$(document).ready(function() {
    var count = 5;
    countdown = setInterval(function() {
        if (count == 0) {
            $('#countdow').hide();
            $('#link-news').show()
        } else {
            $('#countdow').text(count);
            count--
        }
    }, 1700);
    $('#link-news').click(function() {
        var urls = $('input[name=linknexttop]').val();
        if (urls == 1) {
            $('input[name=linknexttop]').val(2);
            $.ajax({
                type: "GET",
                url: domain + "click.html",
                data: "code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b",
                contentType: "application/json; charset=utf-8",

                success: function(html) {
                    //alert(html);
                    window.location = html;
                }
            })
        }
    })
});

After waiting in 5 seconds, it will show:

(#2):

 <div id="countdow">Please wait ...</div>
    <a href="javascript:(0)" onClick="return false" id="link-news" style="display:none;"><img src="en_tran.png" border="0" name="imgTag" /></a>
    </div>

Now, I want to send data to click.html (in #1), without click into image imgTag (in #2). Is there possible to do it with JavaScript?


Rule for playing: "I am allowed to insert my code bellow his original code only; so, I am not allowed to change anything in his code. And, the most important: code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b is random.".


Community
  • 1
  • 1
g8312437
  • 49
  • 8

2 Answers2

1

You can trigger the $('#link-news').click function by calling $('#link-news').click() after the 5 seconds countdown.

Or you can directly call the ajax call in the click function.

    if (count == 0) {
        $('#countdow').hide();
        $('#link-news').show();
        $('#link-news').click(); /* This will trigger the click event without actually clicking on the image */
    } else {
        $('#countdow').text(count);
        count--
    }
DigitalDouble
  • 1,747
  • 14
  • 26
  • HoneyBEE's answer is much better though. `trigger('click');` is much faster according to this thread: http://stackoverflow.com/questions/9666471/jquery-advantages-differences-in-trigger-vs-click – DigitalDouble Aug 12 '15 at 05:10
1

you can trigger click function without clicking on it using trigger function of jquery.

$( "#link-news" ).trigger( "click" );
Sindhoo Oad
  • 1,194
  • 2
  • 13
  • 29