Onclick new window?

How to make this code open a new window:

<! --- 
<button class="button" onclick="window.location.href='https://www.upwork.com/freelancers/michaelkiger';">Contact Owner</button>
--->

Here is how to post code in the forum

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the ā€œpreformatted textā€ tool in the editor ( </> ) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (ā€™).

1 Like
  1. You must use <!-- --> just for HTML comments

  2. You donā€™t use HTML comment tags correctly. You must write <!-- --> instead of
    <! --- --->

If clicking something navigates user from the page it should be an anchor tag (<a>). Buttons are for actions on the page.

Yes, usually it would be in an anchor tag. This application of the button class with the url does work. It goes to the url ā€˜onclickā€™ but it does not open in a new window. I tried using target=_blank to no availā€¦ this is part of a css style sheet. I am hoping to avoid re-writing half the style sheet just to make it open in a new window ā€˜onclickā€™ :slight_smile:

Because target=__blank is for anchor tag.
For window itā€™s window.open(url).
Nevertheless, it still should be an anchor tag.

Ty, however I did try window.openā€¦ maybe I did not have the syntax correct for the entire line of codeā€¦ will try again and let you know.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.