Out of the comment the problem was that the button was inside of a form
element.
The problem is that a button without a type
attribute will submit the form
, which would (not sure if in every browser) result into the described problem, that the window.location.href = ...
has no effect and that the page would be redirected to the url defined in action
. If action
is not defined in the form
then it is the the current url.
You have different options to solve this:
- You could move the button out of the form (if it would not affect usability)
- Change the
type
of the button tobutton
(<button type="button">View Monthly Purchase</button>
) - the default behavior without a type issubmit
- You could place a
return false;
at the end of youropenPage
function to prevent the default behavior (this is similar to 2. but with the difference that thebutton
would still be marked as asubmit
button which could be important for usability in some situations).