I a, developing a site that has an auto-redirect on page load whereby it loops through a sequence of pages. This works perfectly. I also have a link I click to stop the auto-redirect. The auto-redirect uses a function called redirTimer() and the "stop" link calls a function called stopredir() - The latter also adds a suffix to the URL of the "Next Page" link so it changes the hyperlink from example.com/page2 to example.com/page2&noslide - Both of these functions work perfectly.

What I need to do now, also on page load, is check for that &noslide variable so I can call the stopredir() function right away if it exists. I don't want the user to have to click the stop button again if they already clicked it on the previous page. I have got a noslide() function to check for this but it isn't working.

When my page loads, I am calling the noslide() function after the redirTimer() function.

The redirTimer() still starts up automatically, even if it was stopped on the previous page.

I have checked and the variable has been added to the end of the URL and the redirect was stopped when I clicked it. So the noslide() function is clearly not working.

Please can somebody tell me what I am doing wrong?

AussieJohn
—
2012-11-10T10:27:20Z —
#2

Your URL structure isn't quite correct. When you link to a place using an <a> tag, you need to also specify the protocol (e.g. http:// or ftp:// ). When you want to add a query string to a URL, you need to start the query string with a question mark subsequent variables can then be separated by an ampersand.

So, your link for next-nav would then end up looking like

<a class="next-link" href="http://example.com?noslide=true">NEXT</a>

Next up, the way to get URL parameters in JavaScript doesn't have a nice built-in method like .NET for example, but a simple helper function can make it pretty easy

function screwWithAnchors () { //I'm lazy... get all anchors, loop through them, take their href attribute and append the string "?noslide", or #noslide should be fine too //have an id on the one anchor that turns the automation back on again //have your loop above test for it first before appending ?noslide }

Something like that.

In other words, always check for noslide before running the redirect/carousel/whatever thing, and only if it's safe, run it. You'd still have a stop() for when people have started out with it running and want to stop it with a button click, and it would also call screwWithAnchors, but I like the idea of very first thing JS checking what the user did before running stuff.

You might have found what didn't work if you'd taken your if (Request.QueryString["noslide"])and turned it into an alert to see if "noslide" was being seen by JS. Alert is the poor man's debugger but it's pretty regular by me to check everything. I expect some value, but I'd better check the value actually gets seen or that I didn't typo or something.cuz I always typo or something