'Load a page with onclick method of an html button with parameters in the url

I'm modifying a webpage and I would like to create a button that onclick it loads me a new page in the same window. For example, for a link to a webpage with some parameters it could be:

<a href="www.mypage.com/page?param1=abc&param2=345">LINK TO THE WEBSITE</a>

If I do this, the link loads correctly the website. If I modify it to:

<a href=javascript:window.open("www.mypage.com/page?param1=abc&param2=345", "_self")>LINK TO THE WEBSITE</a>

I'm successful too. However, I would like to implement this on a button. Therefore I have:

<button
   onclick="javascript:window.open('www.mypage.com/page?param1=abc&param2=345', '_self')"
</button>

However, now it loads "www.mypage.com/page", and the parameters are erased, even I can see in the source code of the website they are there. Why? How can I implement this with a button?



Solution 1:[1]

you could wrap the button into the href link.

for example:

<a href=javascript:window.open("www.mypage.com/page?param1=abc&param2=345", "_self")><button>Click me</button></a>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samy