Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I specify an anchor tag behaves like a hyperlink, without an href and without an anchor name?
    primarykey
    data
    text
    <p>Okay so this one has some similar threads but I couldn't find anything that nailed it on the head, so here we go.</p> <p>I'm trying to simulate a link using the anchor tag, like so:</p> <pre><code>&lt;a onClick="javascript: DownloadPorn();"&gt;Click Here!&lt;/a&gt; </code></pre> <p>All of this works fine and dandy; the link shows, I can click it, and my javascript method is successfully executed.</p> <p>The question here, is how can I correctly force the link to display in the 'same manner' as an actual 'HTML Link'? Or rather, in the 'same manner' as if I were to have an href in the above mentioned tag; like so:</p> <pre><code>&lt;a href="#" onClick="javascript: DownloadMorePorn();"&gt;Click Here!&lt;/a&gt; </code></pre> <p>Now... THIS Code snippet forces the link to display in the manner that I expect it to, but in using this method, when a link is clicked, the scroll location is bounced back to the top.</p> <p>It's probably clear, that this is not an intended behavior for the framework I am trying to develop. If anyone has any suggestions to overcome this particular issue, I would greatly appreciate your input.</p> <p>--- While typing this all up, I considered that I could place a static anchor at the top of the screen( say 0,0 or -,- ), and force all of my links to reference that anchor. If anyone sees any viability in this solution, I'm likely to explore it.</p> <p>--- Edited ---</p> <p>Accepted Answer:</p> <p>In order to have an anchor behave as a hyperlink, without manipulating the browsers current position; utilize a Javascript method returning nothing(?) in the href attribute, or a valid return of 'false' in one of the alternate event handlers for an anchor, I.E. the onClick method.</p> <p>Possible solutions:</p> <pre><code>&lt;a href="javascript: DoSomething();"&gt;Link&lt;/a&gt; &lt;a href="javascript: void(0);" onClick="javascript: DoSomething();"&gt;Link&lt;/a&gt; &lt;a href="#" onClick="javascript: DoSomething(); return false;"&gt;Link&lt;/a&gt; </code></pre> <p>Thanks again, everyone.</p> <p>--- End Edit --- </p>
    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.
 

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