How to check with javascript if connection is local host?

前端 未结 12 1855
孤独总比滥情好
孤独总比滥情好 2020-12-23 08:45

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

The reason why I want to do that is that when I developing I like to make sure

12条回答
  •  借酒劲吻你
    2020-12-23 09:27

    You could detect in one of your code behind pages with c#, like this:

    if ((Request.Url.Host.ToLower() == "localhost"))
    {
        // ..., maybe set an asp:Literal value that's in the js
    }
    

    Or if you want to do it from client script, you could check the value of window.location.host.

    if (window.location.host == "localhost")
    {
        // Do whatever
    }
    

    Hope this helps.

提交回复
热议问题