如果连接是本地主机,如何检查javascript? [英] How to check with javascript if connection is local host?

查看:74
本文介绍了如果连接是本地主机,如何检查javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果页面加载在我的本地计算机上,我想查看我的javascript。

I want to have a check in my javascript if the page loading up is on my local machine.

我之所以要这样做是因为当我开发我喜欢确保我的服务器端(C#)验证都正常工作。所以我喜欢看到客户端和服务器端都出现错误。

The reason why I want to do that is that when I developing I like to make sure that both my server side(C#) validation is working correctly. So I like to see both the client side and server sides errors to show up.

因此,当我测试时,我的jquery验证中有一个标志,它总是让我无效数据通过。通过这种方式,我可以一次看到客户端和服务器错误。

So while I am testing I have a flag in my jquery validate stuff that just always lets invalid data go through. This way I see the client side and server errors at one go.

然而,现在我必须手动进行从开发到生产的来回切换。 / p>

However right now I have to manually go and change back and forth when going from development to production.

推荐答案

location.hostname 变量为您提供当前主机。这应该足以让您确定您所处的环境。

The location.hostname variable gives you the current host. That should be enough for you to determine which environment you are in.

if (location.hostname === "localhost" || location.hostname === "127.0.0.1")
    alert("It's a local server!");

这篇关于如果连接是本地主机,如何检查javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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