-->
Page 1 of 1

Page change

PostPosted: Fri Mar 17, 2017 4:14 am
by potz
Hi

Using this example
http://www.esp8266.com/viewtopic.php?f=29&t=3787

Instead an ON/OFF button I would like to go to another page. Of course on the new page a betton to go back. How to code the page change?

Thanks

Re: Page change

PostPosted: Fri Mar 17, 2017 9:00 am
by martinayotte
This button code will go to another page :
Code: Select all<input type='button' style='width:100px;height:30px' value='Page2' onClick='window.location.replace("/page2");'/><br>

Re: Page change

PostPosted: Fri May 05, 2017 6:37 am
by potz
thanks for you answer but it's not clear for me how to insert the code for page 2 :

[code][/void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}

// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();

// Match the request

int value = LOW;
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, HIGH);
value = HIGH;
}
if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledPin, LOW);
value = LOW;
}

// Set ledPin according to the request
//digitalWrite(ledPin, value);

// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");

client.print("Led pin is now: ");

if(value == HIGH) {
client.print("On");
} else {
client.print("Off");
}
client.println("<br><br>");

//I would like this on page 1
client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");


//I would like this on page 2
client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");


client.println("</html>");

delay(1);
Serial.println("Client disonnected");
Serial.println("");

}
code]
thanks

Re: Page change

PostPosted: Mon May 08, 2017 9:24 pm
by atexit8
Do you need a second page?

It seems that depending on the value of a variable, you will want to have if-else
Code: Select allclient.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");

or
Code: Select allclient.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");