Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Josh Keenan
Josh Keenan
19,437 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.