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.