Reputation: 21
I'd like to have a click on a button reload the page and change the text inside the button.
For reload I got:
Javascript:
function reloadPage(){
window.parent.location = window.parent.location.href;}
HTML:
<button type="button" onClick="reloadPage()">Start</button>
<script src="reloadpage.js"></script>
After click, the text in the button must change from "Start" to "Try Again!"
How can I do this?
Thank you.
Upvotes: 0
Views: 1580
Reputation: 29
You could do this by adding a query string on reload, and then have a script that detects the query string and changes the text of the button onload.
JavaScript:
function reloadPage(){
window.parent.location = window.parent.location.href+"reload=true";}
function checkQString(){
// get query strings and store reload qstring in variable
if (reload) {
document.getElementById('btn').innerHTML = 'Try Again!';
}
HTML
<button id='btn' type="button" onLoad='checkQString();' onClick="reloadPage()">Start</button>
<script src="reloadpage.js"></script>
Upvotes: 1
Reputation: 1205
You can use Cookies. With js you can use https://plugins.jquery.com/cookie/ Or can use server side cookies
Upvotes: 0