sardine sardine - 6 months ago 8
HTML Question

Secure or enable the 'href' attribute of links with jQuery or Javascript

I need a way to force/secure the href attribute of an

<a>
-tag, because it gets disabled by unknown js.

I have a webpage that uses a template (this: http://templated.co/visualize). When you click on a thumbnail, it triggers javascript that opens a photograph and darkens the rest of the screen nicely. The HTML that triggers the javascript looks as follows:

<section class="thumbnails">
<div>
<a href="images/thumb_big.png">
<img src="images/thumb.png" alt="" />
<h3>Overview</h3>
</a>
</div>
</section>


I however don't need it for photographs: I want the clickable thumbnail to open a modal. I adjusted it accordingly:

<section class="thumbnails">
<div>
<a href="" data-toggle="modal" data-target="#myModal">
<img src="images/thumb.png" alt="" />
<h3>Overview</h3>
</a>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<img style="float:left" src="images/thumb_big.png" />
<p><a href="overview.html">Overview</a> beinhaltet eine Auflistung</p>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</section>


The modal works but the href attribute of the link
<a href="overview.html">
inside of it gets disabled. It just isn't there anymore, when I check the html in firebug, it shows that it's only an empty
<a>
-tag with some css-attributes added. I can't find the passage in the javascript files of the template that do this.
So I'm looking for a javascript or jquery way to overwrite this!

Is there a way to 'force' the href attribute onto a link in the index file script section?

Or to force-secure the href attribute?

Answer

You can try this code :

<a href="javascript:void(0)" onclick="alert(1);">test</a>