This is old, but still relevant with Version 4.9.5 for wordpress, so I answer with my solution for this:
Wordpress filters out any Javascript you use in your Posts or pages, that is why your code gets lost. I did the following steps to add a "javascript:" Link:
- Add the Link you want to your post, use "#" as the href and add a id to the tag (in Text-Mode of the Editor):
<a href="#" id="idOfYourLink">This is my JS Link</a>
- Install a Custom Javascript Plugin. I used Simple Custom CSS and JS
- Add the Javascript you want with help from the plugin:
jQuery(document).ready(function( $ ){
function yourFunction() {
alert("It works");
}
jQuery('#idOfYourLink').on("click", yourFunction);
});
The important part is adding the on-Handler to the Link you want to use. Now the Javascript is loaded right after the page got loaded. And a click on the link will call the function yourFunction