+ 1
Why location.reload (true) doesn't work!?!?
In this game, I wanna reload the page without leave. if (window.confirm("Do you want to play again?")) { location.reload (true); } I tried this code in my PC and it worked but when I try this code on sololearn mobile editor it doesn't work. I don't know if it doesn't work only my phone or not. Please explain this problem if you know or if there is another solution of reloading page without leave let me know, please. https://code.sololearn.com/WRJbrVs8HDtG/?ref=app
5 Answers
+ 3
https://code.sololearn.com/WATKHi1aqlnh/?ref=app
In computer browsers your reload reload the location and so the game looks restarted.
In Sololearn, it's a web view app with default is the code tabs, so reload will not go into the run directly.
I have built the restart feature for you in the above correction.
For the gameplay, there are two problems now:
1. You can cheat by keep pressing the same green and until the score reaches 2700 to win. You'll need to remove event listener which is an anonymous function. I'll show you how after you digest the restart feature.
2. After restart the new no problem can still trigger a lost. Reason same as above. The red flag is still attaching to the tiles and are not removed. Same as 1, I'll follow up after you come to understand the restart feature and the problem associated with your anonymous event listener.
+ 2
Thanks a lot Gordon. I know this problems but I don't find any solution.
+ 2
If you are prepared,
Now we proceed,
There are different ways.
One of which is this:
https://code.sololearn.com/W6NpiFj2L4kt/?ref=app
Second is container.innerHTML == ""
Then use createElement and appendChild to recreate the span dom
Third is use named function as the event listener, so you can use removeEventListener to remove them
+ 2
If the event listener is an anonymous function, yes. Create, style, then insertBefore then remove the original span
+ 1
As I uderstood, We need to create new span after each click, am I right?