0

I'm trying to make a function that will changes the page and marks the selected div (the div is in the other page), The problem is I the function cuts off because its causing the page to refresh.

Here is the javascript code:

    function movePack1(){
    var pac1 = document.getElementById("pack1");
    window.location.href="enclosures.html";
    pac1.style.boxShadow = "0px 0px 5px blue";
}
Hawanity
  • 13
  • 7

1 Answers1

1

You cannot do this in the way you are attempting with client side JavaScript.

If you are trying to execute a dynamic action on a page when it loads, consider passing a GET parameter and then doing something with that on the new page.

window.location.href="enclosures.html?action=shadowpac1";

Then in enclosures.html you would write JavaScript which checks for the "action" GET parameter. If the "action" parameter is equal to "shadowpac1", then you apply your styles.

Look at the following two posts:

  1. How to parse out a GET parameter - How to retrieve GET parameters from JavaScript
  2. How to use DOMContentLoaded to run the function doing the parsing-and-styling after the DOM is loaded: https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
cmorr
  • 105
  • 8