I'd like to use a button on a homepage that when it links to the new page, changes the background color of the new page. In the code, I have two buttons. One is the boring button. It links to the page and does nothing else. The other is the purple button, which is supposed to link to the same page, and change the background color.
I've already tried linking both of the pages to the same script document. I've also tried using the 'DOMContentLoaded' event listener, which didn't work either.
Home page code:
<button id="boringBtn">Press this button to go to a new page and do nothing</button>
<button id="purpleBtn">Press this button to go to a new page and change the color</button>
<script src="link-script.js"></script>
link-script code:
function newPage() {
window.location = "linked-page.html";
}
function newPageWithColor() {
window.location = "linked-page.html";
document.body.style.background = "purple";
}
document.getElementById("boringBtn").onclick = newPage;
document.getElementById("purpleBtn").onclick = newPageWithColor;