如何运行jQuery脚本,如果HTML页面的主页...? [英] How to run jquery script if html page is the home page...?

查看:133
本文介绍了如何运行jQuery脚本,如果HTML页面的主页...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与外部团队合作,与我们的网站,他们最近增加了我的脚本到网站的母版的.NET的一个...好它并终于得到我的脚本运行,但现在......它加载横幅每一个页面的网站上。

I'm working with an external team with our website and they recently added one of my scripts to the .NET MasterPage of the site... well it did finally get my script running but now... it loads Banners on 'every' page on the site.

我怎么能写一个如果声明说基本上是说......如果这是主页...运行此脚本...如果不是不...?

How can I write an 'if' statement that basically says... if this is the home page... run this script... if not don't...?

推荐答案

我张贴另一个答案的情况下,你无法实现母版页的解决方案。

I'm posting another answer in case you can't implement the Master Page solution.

您可以使用标记元素告诉jQuery的它的主页,因为URL方案较早发布可以轻松打破。

You could use a flag element to tell jQuery it's the homepage, because the URL solutions posted earlier can easily break.

在某处你的网页内容,只需将这个。

Somewhere in your Homepage content, simply place this.

<span id="homepage-flag" style="display: none" />

然后使用jQuery检查元素存在和运行code。这是一个pretty较差的解决方案,但如果你不能让我的其他答案工作,将工作。

And then using jQuery, check if the element exists and run your code. It's a pretty poor solution but it will work if you can't get my other answer to work.

if($("#homepage-flag").length > 0) {
    // run code for homepage
}

这篇关于如何运行jQuery脚本,如果HTML页面的主页...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆