locked
can someone help me in creating JS code RRS feed

  • Question

  • User2001694453 posted
    i need a java script code which would make my website or user's browser think that the user has clicked anywhere on the website even if the user hasn't done it can someone create it for me
    Apologies for my bad english
    And thanks a lot for having a look at my question
    Have a good day
    Tuesday, May 21, 2019 1:12 AM

All replies

  • User-2054057000 posted

    For example you can create a click event on some html element of your web page:

    <button id="button1">Click</button>
     
    $("#button1").click(function () {
        alert("I am clicked");
    });
    

    Now you can click the element after 2 seconds time after the page loads using the .setInterval() method like this:

    setTimeout(function(){ $("#button1").click(); }, 2000);

    Check these 2 references below:
    1. jQuery Click Event
    2. setTimeout()

    Tuesday, May 21, 2019 4:15 AM
  • User2001694453 posted
    thanks a lot but it doesn't auto click on my website I've tried to add both the codes together as well
    Tuesday, May 21, 2019 5:32 AM
  • User-1174608757 posted

    Hi yoyoaman ,

    According to your description, I have made a sample here. Here is the code.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-3.3.1.js"></script>
        <script>
            function bur()
            {
                alert("click event");
    
            }
            $(function () {
    
                setTimeout(function () {bur()},3000)
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>        
               
                <input id="Button1" type="button" value="button"  onclick="bur()"/>   
            </div>
        </form>
    </body>
    </html>
    

    Best Regards

    Wei

    Tuesday, May 21, 2019 5:46 AM
  • User-2054057000 posted

    thanks a lot but it doesn't auto click on my website I've tried to add both the codes together as well

    Check the Browser's console window if you are getting any JS error.

    Tuesday, May 21, 2019 12:13 PM
  • User2053451246 posted

    Sounds like you are trying to get around the security feature that prevents a browser from showing popup windows if the user does not interact with the page.  If that is your goal you will not be able to achieve it.

    Tuesday, May 21, 2019 1:23 PM
  • User2001694453 posted
    exactly I've tried to ask this question like this but people here didn't get that that is why i had to ask this question like this but are you sure it is not possible in any way not even with HTMLElement.click method
    Tuesday, May 21, 2019 1:43 PM
  • User-1174608757 posted

    Hi yoyoaman,

    According to your description,firstly it needs a trigger to run a script in the page, so I think you want to trigger the script whenever you want when user visit the website,right?

    I think it is not safety for users,if users just visits some shopping website, it's horrible that it just run a script to let them pay the list.

    Else, browser has its security system, it will prevent script injection.So,I hope you could share the detail what you want and which situation you need to trigger the script,

    Best Regards

    Wei 

    Wednesday, May 22, 2019 5:22 AM
  • User-857013053 posted

    <body id="clickNow"></body>

    <script>

    $(document).ready(function(){

    $('#clickNow').click(function(){

    alert('Don't click me');

    });

    });

    </script>

    Thursday, July 18, 2019 5:33 AM
  • User-474980206 posted
    Browser security prevents this. You can call any click handler directly, but the browser will know it’s not a real click, you can not open a window for example unless security allows.

    Call events will depend on how events are hooked up. If the hooks are all jquery, then you can send a jquery event. If the handler is attend directly to an element (click, change, etc), then you can call directly. If the more modern add event listener is used, then you will need to replace this function with your own before its called.
    Thursday, July 18, 2019 5:46 PM