Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recommend to bind events with jquery, then later programmatically click them also with jquery. However, if you just can't include jquery:</p> <pre><code>function AnchorClick(anchorId) { var elem = document.getElementById(anchorId); if (elem.onclick!=null) { elem.onclick(); } else if ((elem.href!=null) &amp;&amp; (elem.href!="")) { var matches = /^javascript:(.+)$/.exec(elem.href); if ((matches!=null) &amp;&amp; (matches.length&gt;1)) { // the href is a javascript snippet, execute it var tempUndefined; var script = "({func:function(){"+matches[1]+"}})"; var json = eval(script); elem.tempFunc = json.func; // set the eval'd function on the item itself so it will be executed with the correct scope elem.tempFunc(); elem.tempFunc = tempUndefined; // eliminate the temp function } else { // the href wasnt a javascript snippet, just navigate to the href window.location = elem.href; } } } </code></pre> <p>EDITED: This above function was updated to now preserve the scope for any href="javascript:" script handler and supports any of the following anchor formats:</p> <ul> <li><p>anchor with regular script onclick="" attribute. Note the href="javascript:void(0)" is so the link will be rendered as focusable so that in addition to using the mouse, disabled users can use the tab key to navigate to and hit ENTER to cause the click action:</p> <p>&lt;a href="javascript:void(0)" onclick="dostuff();"&gt;fooContent&lt;/a&gt;</p></li> <li><p>anchor with javascript href</p> <p>&lt;a href="javascript:dostuff();"&gt;fooContent&lt;/a&gt;</p></li> <li><p>anchor with normal navigation link</p> <p>&lt;a href="http://www.yahoo.com"&gt;fooContent&lt;/a&gt;</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload