Use action links with # or javascript:void(0)

Sometimes, hyperlinks are used to trigger a particular action rather than opening to a given page or resource (such as to Open widget to a specific article or category.)

If you've imported content from somewhere else, there is a chance you may have added links with this format (or you may have them there on purpose for specific functionality!).

Standard conventions for these types of hyperlinks are to set the link's URL to be either # or javascript:void(0).

The problem

Our editor will usually try to encode that HTML on-save, so instead of getting javascript:void(0), it gets converted to javascript%3Avoid(0), which breaks the link's underlying action.

Solutions

There are two ways to resolve this issue:

  1. Adjust the link URL to use # instead.
    1. This can typically be used in exactly the same way as javascript:void(0) and won't be stripped out by the editor.
  2. Create a snippet that contains the javascript:void(0) text and use that snippet merge code as the URL for these links.

We recommend using the first approach wherever possible, since it is very simple and you can quickly update the URL directly in the article editor.

But if you'd like to try the second:

  1. In the lefthand navigation, go to Snippets.
  2. Select + Create New Snippet. If you're unfamiliar with creating snippets, refer to Create a snippet for more detailed instructions.
  3. Enter a Snippet Name like Javascript Void.
  4. Enter a Snippet Description like This snippet contains the javascript:void() text for use in certain action links, so it won't get stripped out of the editor..
  5. Select the Snippet Content dropdown and select Code Editor:
  6. Copy the code below and paste it into the Snippet Content editor.
    javascript:void(0)
  7. DO NOT toggle the Snippet Content back to WYSIWYG Editor; keep it in Code Editor.
  8. Once you're done making changes, select Create to finish creating your snippet.

With your snippet created, you can use the full merge code as the URL for any hyperlink that you want to use javascript:void(0) in, like this:


Sample hyperlink using the javascriptVoid snippet. Note that the full snippet merge code is used for the URL.