Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Josh Keenan
Josh Keenan
19,652 Points

Can I write a script that doesn't update a page after a refresh

I want to prank my friend, recently he entered the lottery for the first time and he has been planning how to spend all the money, now we also just moved for university so we are skyping regularly now to stay in touch.

I want to share screens with him and make him think I have won the lottery, but he will ask me to refresh the page to prove it. Is there a way to write a script that changes the value of a specific element on a page and keeps it as that whilst the script runs?

So I open the prize page and it will say for example, 'congrats you have won!' instead of 'bad luck, try again' or whatever.

1 Answer

You could write a function that changes the text to display what you want, then call that function when the page loads:

<body onload="myFunction()">

Not sure if this is something you can use, but it works depending on the page you are loading. Cheers.