www.webdeveloper.com
Results 1 to 10 of 10

Thread: Script to simulate mouse click on page load?

  1. #1
    Join Date
    Jun 2009
    Location
    San Diego, CA
    Posts
    2

    Script to simulate mouse click on page load?

    I'm wondering if anyone has heard of or come across a script that automates a mouse click on a certain part of the page when it loads. For example, I want the page to load and then automatically have the mouse click in the upper right corner of the screen, about 5px from the top and 5px from the right.

  2. #2
    Join Date
    Oct 2006
    Posts
    93
    What are you trying to click? A button, radio button, ...?

  3. #3
    Join Date
    Jun 2009
    Location
    San Diego, CA
    Posts
    2
    I need it to click inside a certain div area to close a pop up...if that makes sense

  4. #4
    Join Date
    Oct 2006
    Posts
    93
    Hmmm. I've never tried simulating a click on a div.
    Maybe try

    <div id="MyDiv></div>

    document.getElementById('MyDiv').onclick();
    or
    document.getElementById('MyDiv').click();

    but I would be surprised if either worked honestly.

  5. #5
    Join Date
    Oct 2006
    Posts
    93
    or possible....

    <div><a href="javascript:void();" id="MyLink"></a></div>

    document.getElementById('MyLink').onclick();
    or
    document.getElementById('MyLink').click();

    I'm almost certain you can simulate a link click, and since it is inside the div it may simulate clicking there as well.

  6. #6
    Join Date
    Jun 2006
    Posts
    384
    Posting the code would make it lot easier to understand what you're trying to achieve.

  7. #7
    Join Date
    Jan 2014
    Posts
    1
    .......................................................................................
    html
    ......................................................................................


    <input type="submit" name="Submit" value="Find Product"
    onclick="return incrementClicksTest('8','true')" class="buttonSubmit">

    ............................................................................................
    javascript
    ..............................................................................................
    incrementClicksTest = function(i,x)
    {
    alert(i);
    return true;
    }

    document.getElementsByTagName("input")[0].click();

    ............................................

  8. #8
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,133
    When people want "Click button" routines, it is often linked to a "Vote for us" type button.

    If its not then theirs some other motive to want a click automated, that rings alarm bells or sends up warning flares for me and you have to ask what is the motive for clicking inside a DIV, what would be in the div to need it to be clicked.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  9. #9
    Join Date
    Jan 2014
    Posts
    1
    Do you have JQuery on board? Have you tried jquery.trigger?

    http://api.jquery.com/trigger/


    Quote Originally Posted by \\.\ View Post
    When people want "Click button" routines, it is often linked to a "Vote for us" type button.

    If its not then theirs some other motive to want a click automated, that rings alarm bells or sends up warning flares for me and you have to ask what is the motive for clicking inside a DIV, what would be in the div to need it to be clicked.
    Maybe they're scraping product data from their supplier's web site (because there is no other automatable way to get the info) and they need their script to click the "search" button, or maybe they're developing automated tests for their own SAAS application, or who knows. I can imagine of any number of perfectly legitimate reasons to want to do it.

    I don't want to jump down this particular responder's throat, but their post highlights an issue I feel strongly about and I want to make these points to every potential technical forum post responder who reads this:

    A whole lot of us techies are in circumstances resulting from choices of others that we have no control over. It's frustrating enough just enduring our situations and wrangling with the tech we're more-or-less forced to work with without having our fellow techies questioning our motives or the tech choices or approach choices that have been made. If we question people's motives or their choices, then we force everyone to write all kinds of irrelevant background every time they post a question! That's frustrating not only to the people posting questions, but also to people who are here to try to answer people's questions. Tons of people are managing to do all kinds of terrible things all the time. Clearly, if someone wants to do something evil, and there's a way to do it that is within reach for them, they're going to find that way whether you answer their question or not. Just because you can't imagine what possible legitimate reason they might have for what they're doing doesn't mean there isn't one.

    Please folks, let's not appoint ourselves judges or juries, let's just answer questions to the best of our ability.

  10. #10
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by j.blaise.n View Post
    I need it to click inside a certain div area to close a pop up...if that makes sense
    What caused that popup to open in the first place?

    Is someone paying you to have it there?

    If it can be closed by a user click, then there must be a function already available to do it.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles