【问题标题】:Adding JavaScript to Classic ASP (new to this)将 JavaScript 添加到经典 ASP(对此的新功能)
【发布时间】:2013-06-21 22:50:48
【问题描述】:

我在 ASP.NET 中有一个网站,当人们访问该网站时,它会弹出一个小 cookie 警告。我不应该做的是复制这个,但是对于一个用经典 ASP 编写的站点(不是我的错),我知道代码可以工作,因为它可以在当前站点上工作。我如何引用 JavaScript 以及它与页面相关的位置?如果我的问题看起来真的很愚蠢,我对这一切都很抱歉。提前感谢您的帮助。这是我正在使用的代码:

div id="cookieConsentRequest" runat="server" visible="true

            <p><span class="queryIcon"></span>some text here                <a href="#" class="acceptCookiesAnchor acceptCookieSmall acceptCookie" runat="server">I accept</a>
            <a href="Javascript:;" class="infoCookie" title="Tell me more about these cookies">Click here for more info</a>
            <a href="Javascript:;" id="alertBannerHide" class="hideButton" title="Hide this">Hide</a>
            </p>
        </div>
        <!--[if IE 6]>
        <script language="javascript" type="text/javascript">
            $(document).ready(function () {
                $('.alertBanner').css("top", ($(window).height() - 29));
            });
        </script>
        <![endif]-->
        <script type="text/javascript">
            $(document).ready(function () {
                $('.alertBanner').css("left", (($(window).width() / 2) - 360));
                $('.alertBanner').delay(1000).slideDown('slow');
                $('#alertBannerHide, a.denyCookie').click(function () {
                    $('.alertBanner').slideUp('slow');
                    $('.cookieInfoWindow').fadeOut('fast');
                });
                $('.cookieInfoWindow').css("left", (($(window).width() / 2) - 320));
                $('a.acceptCookie, .infoCookie').click(function () {
                    $('.cookieInfoWindow').fadeIn('fast');
                });
                $('#cookieInfoWindowHide, .cookieInfoWindow a.denyCookie').click(function () {
                    $('.cookieInfoWindow').fadeOut('fast');
                    $('.alertBanner').slideUp('slow');
                });
            });
        </script>
        <div class="cookieInfoWindow">
            <h3><a href="Javascript:;" id="cookieInfoWindowHide" class="hideButton" title="Hide this">Hide</a>Cookies used on this web site</h3><br />

            <p>some text here</p><br />
            <p>some text here <a href="http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55539" class="externalLinkWhite"
             title="Read more about Google Analytics (external link)">Google Analytics</a> some text here.</p><br />
            <p>some text herep><br />
             <p>For more information on how cookies are used please visit the following websites:</p>
             <ul>
                <a href="http://www.microsoft.com/info/cookies.mspx" class="externalLinkWhite" title="Information about cookies on Microsoft.com (external link)">Microsoft Cookie Information</a><br /><br />
                <a href="http://www.allaboutcookies.org/" class="externalLinkWhite" title="All about computer cookies (external link)">All About Cookies</a>
             </ul>
            <p>
                <a id="acceptCookiesAnchor" href="#" class="acceptCookie" runat="server">Yes, I accept the use of cookies as outlined above</a>
            </p>
        </div>
    </div>--> 

对它的状态感到抱歉。

【问题讨论】:

  • “参考 Java”是什么意思?
  • 也许你应该在 .net 中展示你是如何做到这一点的,以使事情更清楚。
  • 您的意思是用于创建 cookie 的 JavaScript?它在经典 ASP 和 ASP.NET 中完全相同,只是将它放在 .asp 页面本身的 &lt;head&gt; 部分中。
  • @SearchAndResQ ,刚刚添加了上面的代码,在 ASP 中尝试过,但其中一些无法工作,因为它只是 .NET。抱歉回复晚了,我很久没登录了
  • 我在该代码中没有看到任何与 Java 或 .NET 相关的内容。

标签: javascript html cookies asp-classic popup


【解决方案1】:

JavaScript 是浏览器的一部分。您提供希望浏览器与 HTML 内联运行的 JavaScript 或作为 HTML 中引用的 .js 文件。

jQuery,引用their website,是“一个快速、小型且功能丰富的 JavaScript 库。它使 HTML 文档遍历和操作、事件处理、动画和 Ajax 等事情变得更加简单,并且易于操作。使用适用于多种浏览器的 API”。

重要的是,jQuery 提供了$ 语法和cssslideDownfadeUp 等您的代码使用的函数。

因此,您的代码必须引用 jQuery 库。这很容易通过添加以下行before(在&lt;head&gt; 中是可以的,但不一定是最佳实践)您的任何jQuery 代码(使用$jQuery 的JavaScript):

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

这添加了对托管在其服务器上的最新(发布时)jQuery 代码的引用。也可以download the library here在本地引用。

【讨论】:

  • 谢谢你,那种帮助。 (我添加了一个页面加载事件来检查,新窗口会打开)但它仍然不会呈现。我把所有的 css 和图片等都拉了出来......
  • 请详细说明。 JSFIddle 也可能有帮助。
  • 不知道这是什么对不起。如果你访问这个站点 --> claremont.im 底部弹出的小 cookie 警告就是这个脚本的来源。当放入 ASP 页面时,文本会显示(分成 9 行),但它不会出现在小框或任何东西中,而是位于页面底部。
  • 您似乎缺少图像
  • 图片肯定在那里,在正确的文件夹等中。我有点不确定你的意思
猜你喜欢
  • 2011-04-07
  • 1970-01-01
  • 1970-01-01
  • 2012-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多