Hello guys, i’m currently developing a site with arduino project which is WEB SWITCH.
I got codes like this…
//Prints the ON Buttons
client.print("<INPUT TYPE=\"button\" VALUE=\"ON ");
//Prints the OFF Buttons
client.print(" <td><INPUT TYPE=\"button\" VALUE=\"OFF");
It prints ON and OFF button in my site.
whenever i click those buttons…
for example, i clicked on… the location will be “192.168.0.200/?Hvar”
after visiting that location i want it to instantly redirect to “192.168.0.200/”
is it possible?
Please help me.
I think that what you are requesting may astonish the user, but I will let it be.
The onClick method could execute a function that loads from one URL, waits a while, and then loads from another.
Another way would be to add an onLoad method. The onClick method would load one URL, and the onLoad method would execute a function that loads another URL. I am uncertain whether onLoad is allowed on a button, however.
Caveat: I haven't tried this myself, but it may point the way to a plan.
I wonder if the OP is really wondering if it is possible for the Arduino code to create one URL on one occasion and a different URL for the same button on another occasion. If so, the answer is YES.
You could send an HTTP 302 response with the location you want to redirect the user to: HTTP 302 - Wikipedia
for example, i clicked on.. the location will be "192.168.0.200/?Hvar"
after visiting that location i want it to instantly redirect to "192.168.0.200/"
is it possible?
You might look at the below tutorials on redirection setting the refresh time to 0.
That sounds like... not very good behavior that you're trying to achieve.
I'd have the onClick fire off an XHR to a different URL answered by the Arduino that would just do the action and not have to return anything to the client other than a 200 OK. Less work for the Arduino, and a better UX for the user.
Also, you forgot to use the F() macro on those string constants you're sending to the client.
The redirects are very common with the "click thru" sites that collect data and which count clicks to pay people for the click thrus they generate.