js獲取本地ip兼容方法,js獲取本地文件及目錄的方法推薦

js獲取本地ip兼容方法
js獲取本地ip的兼容方法,兼容WebRTC,WebKit和Moz 。
1、獲取PeerConnection方法,火狐用mozRTCPeerConnection , chrome用webkitRTCPeerConnection 。
如果ip不存在,則新建一個 。
使用正則匹配ip地址 。
監聽ip發生改變事件 。
使用方法如下
方法總結1、獲取PeerConnection方法,火狐用mozRTCPeerConnection,chrome用webkitRTCPeerConnection 。
2、如果ip不存在,則新建一個 。
3、使用正則匹配ip地址 。
4、監聽ip發生改變事件 。
5、使用方法如下 。
js獲取本地文件及目錄的方法推薦<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>3</title>
<script>
function getFullPath(obj) {
if (obj) {
//Internet Explorer
if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
obj.select();
return document.selection.createRange().text;
}
//Firefox
if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
if (obj.files) {
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
//兼容chrome、火狐等,HTML5獲取路徑
if (typeof FileReader != "undefined") {
var reader = new FileReader();
【js獲取本地ip兼容方法,js獲取本地文件及目錄的方法推薦】reader.onload = function(e) {
document.getElementById("pic").src = http://www.baifabohui.com/smjk/e.target.result +"";
}
reader.readAsDataURL(obj.files[0]);
} else if (browserVersion.indexOf("SAFARI") > -1) {
alert("暫時不支持Safari瀏覽器!");
}
}
}
function showPic(obj) {
var fullPath = getFullPath(obj);
if (fullPath) {
document.getElementById("pic").src = http://www.baifabohui.com/smjk/fullPath +"";
}
}
</script>
</head>
<body>
<input type="file" οnchange="showPic(this)">
<img src="" id="pic">
</body>
</html>

js獲取本地ip兼容方法,js獲取本地文件及目錄的方法推薦

文章插圖
以上就是關于js獲取本地ip兼容方法,js獲取本地文件及目錄的方法推薦的全部內容,以及js獲取本地ip兼容方法的相關內容,希望能夠幫到您 。