简体   繁体   English

使用jQuery或Javascript保护或启用链接的'href'属性

[英]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. 我需要一种强制/保护<a> -tag的href属性的方法,因为它会被未知的js禁用。

I have a webpage that uses a template (this: http://templated.co/visualize ). 我有一个使用模板的网页(此文件: 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. 当您单击缩略图时,它会触发javascript,以打开照片并使屏幕的其余部分完全变暗。 The HTML that triggers the javascript looks as follows: 触发javascript的HTML如下所示:

<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. 该模式有效,但其中的链接<a href="overview.html">的href属性被禁用。 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. 它不再存在了,当我在萤火虫中检查html时,它表明它只是一个空的<a> -tag,并添加了一些css-attributes。 I can't find the passage in the javascript files of the template that do this. 我在执行此操作的模板的javascript文件中找不到段落。 So I'm looking for a javascript or jquery way to overwrite this! 因此,我正在寻找一种JavaScript或jquery方式来覆盖它!

Is there a way to 'force' the href attribute onto a link in the index file script section? 有没有一种方法可以将href属性“强制”到索引文件脚本部分中的链接上?

Or to force-secure the href attribute? 还是要强制保护href属性?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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