简体   繁体   中英

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?

you can try to add it like so :

<script type="text/javascript">
   $(".modal-body").find('a').attr('href','overview.html');
</script>

您可以尝试以下代码:

<a href="javascript:void(0)" onclick="alert(1);">test</a>
    <section class="thumbnails">
                                    <div>
                                        <p >
                                            <img src="images/thumbs/01.jpg" alt="" />


                                          <a  href="images/fulls/01.jpg">
                                              Lorem ipsum dolor sit amet
                                          </a>  
                                        </p>

                                    </div>

                                </section>
</section

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM