js获取本地ip和地区
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>Document</title>
</head> <body>
<script type="text/javascript" charset="utf-8">
function get_ip(cb) {
var script = document.createElement("script"),
s = document.getElementsByTagName("script")[0];
script.src = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=jsonp";
s.parentNode.insertBefore(script, s);
var it = setInterval(function() {
if (!!remote_ip_info) {
cb(remote_ip_info);
remote_ip_info = null;
clearInterval(it);
it = null;
}
}, 100);
}
get_ip(function(info) {
alert('你的ip所在地为:' + info.country + info.province + info.city);
});
</script>
</body> </html>
<!doctype html>
<html> <head>
<meta charset="utf-8">
<title>t1</title>
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
</head>
<body>
<h1>点击获取ip</h1>
<br>
<button class="xxx-btn" onclick="aa()">click me</button>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script>
function aa() {
alert(returnCitySN['cip'] + returnCitySN['cname']);
console.log(returnCitySN);
};
</script>
</body> </html>
js获取本地ip和地区的更多相关文章
- js获取访问IP、地区、、当前操作浏览器
js获取IP.地区.当前操作浏览器有什么用呢? 我的回答是用处很多,比如现在的异地登录和对用户常用浏览器做数据分析等. 源代码如下:index.html <!DOCTYPE html> & ...
- js获取本地ip
function getUserIP(onNewIP) { // onNewIp - your listener function for new IPs //compatibility for fi ...
- vue中获取本地ip
一.目的 获取当前访问的ip地址 二.思路 通过使用搜狐的api获取访问ip 三.操作步骤 1.在index.html中添加 <script src="http://pv.sohu.c ...
- Linux编程获取本地IP
#include <stdio.h> #include <sys/types.h> #include <ifaddrs.h> #include <netine ...
- Java获取本地IP地址
import java.net.InetAddress; import java.net.UnknownHostException; public class IpTest { public stat ...
- 获取本地IP地址信息
2012-06-05 /// <summary> /// 获取本地IP地址信息 /// </summary> void G ...
- JS获取客户端IP地址、MAC和主机名七种方法
一.使用JS获取客户端IP的几个方法方法一(只针对IE且客户端的IE允许AcitiveX运行,通过平台:XP,SERVER03,2000).获取客户端IP代码:<HTML><HEAD ...
- Android应用开发提高篇(1)-----获取本地IP
链接地址:http://www.cnblogs.com/lknlfy/archive/2012/02/21/2361802.html 一.概述 习惯了Linux下的网络编程,在还没用智能机之前就一直想 ...
- C# — 动态获取本地IP地址及可用端口
1.在VS中动态获取本地IP地址,代码如下: 2.获取本机的可用端口以及已使用的端口:
随机推荐
- angular 自定义指令详解 Directive
在angular中,Directive,自定义指令的学习,可以更好的理解angular指令的原理,当angular的指令不能满足你的需求的时候,嘿嘿,你就可以来看看这篇文章,自定义自己的指令,可以满足 ...
- Https系列之一:https的简单介绍及SSL证书的生成
Https系列会在下面几篇文章中分别作介绍: 一:https的简单介绍及SSL证书的生成二:https的SSL证书在服务器端的部署,基于tomcat,spring boot三:让服务器同时支持http ...
- Excel的实用函数
在介绍Excel函数前先说明两个概念:公式和函数. 公式:由用户自行设计对工作表进行计算和处理的计算式,以等号"="开始,其内部可以包括函数.引用.运算符和常量. 函数:即是预先定 ...
- Rundeck部署和基本使用
rundeck 介绍 Rundeck 是一款能在数据中心或云环境中的日常业务中使程序自动化的开源软件.Rundeck 提供了大量功能,可以减轻耗时繁重的体力劳动.团队可以相互协作,分享如何过程自动化, ...
- 【转】elasticsearch的查询器query与过滤器filter的区别
很多刚学elasticsearch的人对于查询方面很是苦恼,说实话es的查询语法真心不简单- 当然你如果入门之后,会发现elasticsearch的rest api设计是多么有意思. 说正题,ela ...
- http://codeforces.com/problemset/problem/847/E
E. Packmen time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Windows中的硬链接和软链接(hard link 和 Symbolic link)
先来了解一下Linux中的硬链接和软链接: Linux中的硬链接和软链接 Windows中的硬链接和软链接: 硬链接 从Windows NT4开始,NTFS文件系统引入了HardLink这个概念,它让 ...
- asp.net中利用Jquery+Ajax+Json实现无刷新分页(二)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageTest.aspx.cs ...
- 深入浅出AQS之组件概览
之前分析了AQS中的独占锁,共享锁,条件队列三大模块,现在从结构上来看看AQS各个组件的情况. 原文地址:http://www.jianshu.com/p/49b86f9cd7ab 深入浅出AQS之独 ...
- 关于KVO导读
入门篇 KVO是什么? Key-value observing is a mechanism that allows objects to be notified of changes to spec ...