Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I press a button with Javascript, but stop it after so many clicks?

    I'm really new to Javascript, and really know basically nothing about it. What I want to do is press a skip button on a page, then wait for the next page to load completely before pressing the skip button. I want the script to stop after the first five skips, though.

    I plan on making this into a GreaseMonkey script for my own personal use, if that info is needed, too.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    If each page is a separate url and each "skip" button is created by that page, then you will have to set a cookie to count the total number of clicks so that the value is passed from page to page. But why not simply make each click of the button redirect to the next page, and omit the button from the final page?

    If each new page is loaded into an iframe you will want something like

    Code:
    <input type = "button" value = "Skip a Page" onclick = "skip()">
    
    <script type = "text/javascript">
    var count = 0;
    function skip() {
    count ++;
    if (count == 1) {window.location = "page1.html"}
    if (count == 2) {window.location = "page2.html"}
    if (count == 3) {window.location = "page3.html"}
    if (count == 4) {window.location = "page4.html"}
    if (count >= 5) {window.location = "page5.html"}
    }
    </script>

    Quizmaster: When commuters are squashed together on trains, they are said to be packed in like what?
    Contestant: Eels.

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunately, the pages do not have separate URLs. They appear to be something like frames, but I don't think they really are. Does "dynamic flow" mean anything to you?

    An example of a page I would use this code on is here: https://www.eversave.com/common/dyna...icPollFlow.jsp

    The page will probably not open unless you're signed in, but the ".jsp" file name can maybe give you an idea of what you're supposed to be looking at.
    Last edited by DeadlyFishy; 06-25-2009 at 06:12 PM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by DeadlyFishy View Post
    Does "dynamic flow" mean anything to you?
    Sure - it is something to do with yoga, isn't it?

  • #5
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Sure - it is something to do with yoga, isn't it?
    Well that's no help, but at least I got a laugh!

  • #6
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The original Just Say No! GreaseMonkey script is here..

    Code:
    inputs = document.getElementsByTagName("input");
    var checkedyes = 0;
    var radios=0;
    var firstradio=0;
    var foundradio=false;
    var i=0;
    for(i=0;i<inputs.length;i++)
    {
    	if(inputs[i].type=="radio")
    		{
    			if(!foundradio)
    			{
    				firstradio = i;
    				foundradio = true;
    			}
    			radios++;
    			if(inputs[i].value.toLowerCase()=="no")
    			{
    				inputs[i].checked = true;
    				inputs[i].click();
    				document.body.focus();
    			}
    			else
    			{
    				inputs[i].checked=true;
    			}
    		}
    	
    }
    if (radios>2)
    {
    	inputs[firstradio+2].checked=true;
    }
    
    next = document.getElementById("nextOffer");
    if (next == null)
    {
    	next = document.getElementById("pass");
    }
    if (next == null)
    {
    	next = document.getElementById("bt_cancel");
    }
    if(next == null)
    {
    	for(i=0;i<inputs.length;i++)
    	{
    		if((inputs[i].type=="submit") && (inputs[i].value.toLowerCase()=="skip"))
    		{
    			next = inputs[i];
    			break;
    		}
    	}
    }
    if(next==null)
    {
    	for(i=0;i<inputs.length;i++)
    		{
    			if((inputs[i].value.toLowerCase()=="submit") || (inputs[i].name.toLowerCase()=="submit"))
    			{
    				next = inputs[i];
    				break;
    			}
    		}
    }
    if(next == null)
    {
    	next = document.getElementById("submitbutton");
    }
    next.focus();
    next.click();
    That seems to work a majority of the time for the skipping, though I think some buttons are named differently or something because it doesn't catch them all. Is there a way to modify this code so it will stop after five skips?

    Also, found this in the pages source where I want the skipping to happen

    Code:
    <input type="image" alt="Skip" name="bt_cancel" id="bt_cancel" src="https://images.eversave.com/Images/newsletter/QzGreyskipbtn051408.gif" onClick="return handleSubmit(this);"/>
    That appears to be a skip button, if that helps at all.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    onClick="return handleSubmit(this);"

    I don't see a function handleSubmit() but you could quite easily do something like

    Code:
    var skipCount = 0;
    function handleSubmit() {
    skipCount ++;
    if (skipCount > 5) {return false}

  • #8
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The code snippet that I said appears to be a skip button was from the page source, not from the GreaseMonkey script or anything. I'm still sort of confused. Do you think there's anyways you could just modify the GreaseMonkey script to make it stop after five skips?


  •  

    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
    •