導航:首頁 > 編程語言 > javascript本地路徑

javascript本地路徑

發布時間:2021-02-28 05:20:39

A. js取得本地路徑的代碼

使用javascript來獲取當前url網址非常有用。下面以例子講解:

輸入的網址是(沒有框架):http://localhost:81/Test/1.htm?Did=123
<br>以下為輸出:
<br>
<SCRIPT>

//獲取Url傳過來的值
function Request(name)
{
new RegExp("(^|&)"+name+"=([^&]*)").exec(window.location.search.substr(1));
return RegExp.$2
}

thisURL = document.URL; // http://localhost:81/Test/1.htm?Did=123
thisHREF = document.location.href; // http://localhost:81/Test/1.htm?Did=123
thisSLoc = self.location.href; // http://localhost:81/Test/1.htm?Did=123
thisDLoc = document.location; // http://localhost:81/Test/1.htm?Did=123

thisTLoc = top.location.href; // http://localhost:81/Test/1.htm?Did=123
thisPLoc = parent.document.location;// http://localhost:81/Test/1.htm?Did=123
thisTHost = top.location.hostname; // localhost
thisHost = location.hostname; // localhost

thisU1 = window.location.protocol; // http:
thisU2 = window.location.host; // localhost:81
thisU3 = window.location.pathname; // /Test/1.htm

document.writeln( thisURL + "<br />");
document.writeln( thisHREF + "<br />");
document.writeln( thisSLoc + "<br />");
document.writeln( thisDLoc + "<br />");

document.writeln( thisTLoc + "<br />");
document.writeln( thisPLoc + "<br />");
document.writeln( thisTHost + "<br />");
document.writeln( thisHost + "<br />");

document.writeln( thisU1 + "<br />");
document.writeln( thisU2 + "<br />");
document.writeln( thisU3 + "<br />");

document.writeln( "Did="+Request("Did") );// Did=123
</SCRIPT>

B. html頁面關聯本地Js文件,它的路徑是什麼

<script type="text/javascript" src="/driver/static/js/app/ico/ico/dianhuafuwu.app.js"></script>
SRC裡面寫路徑,相同文件夾下直接寫js名。。
不同文件夾的可以寫絕對路徑(文件夾名/js名.js)和相對路徑。 (../表示一層文件夾。有幾層就寫幾個如三層就../../../js名.js)

C. 如何用javascript操作本地文件

js被設計為沙箱式語言,理論上講是不應該去訪問本地文件系統的。
但是網上有訪問本地文回件的操作,是通過答ActiveXObject。但是這種寫法綁架了瀏覽器,跟IE綁死,所以建議你如果可以的話,最好不要存類似心思,而是通過其他後台邏輯傳送文件內容。

D. HTML中插入javascript本地文件

jquery 也引入一下
並且放在
<script type="text/javascript" src="script.js"></script>的前面

E. javascript 如何分離出本地路徑中的文件名

function getFileName()
{
var value=document.all.ff.value;
var last=value.lastIndexOf("\\");
var filename=value.substring(last+1,value.length);
alert(filename);
}
這樣合適不?

F. 如何通過JS獲取用戶本地圖片路徑

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>get file input full path</title>
<script language='javascript'>
function getFullPath(obj)
{
if(obj)
{
//ie
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select();
return document.selection.createRange().text;
}
//firefox
else if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
if(obj.files)
{
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
</script>
</head>
<body>
<input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
<img id="img" />
</body>
</html>

firefox7+請使用return window.URL.createObjectURL(obj.files.item(0));來獲取地址

G. js 如何獲取當前網頁的本地路徑

varlcal=location.href;
lcal=substring(0,lcal.lastIndexOf(""));

H. 怎樣用js代碼引入本地圖片的路徑

1、本地的圖片?HTML只能來連接網站內自的圖片,即使在本地,也需要先將圖片拷貝到網站內。
2、網頁中引用js文件,象你這樣如果用到圖片路徑等時,要注意的是這個路徑如果用相對路徑表示的話,是網頁與圖片之間的相對路徑,而不是js文件與圖片之間的相對路徑。如果有多個不同的目錄中的網頁文件需要引用一個這樣的js文件的話,最好的解決辦法是用絕對路徑。也就是改成:
imgUrl1=("/images/0.gif")
imgtext1="1111"
imgLink1=escape("/XX.html");
imgUrl2=("/images/00.gif");
imgtext2="222"
imgLink2=escape("/XXX.html");

I. 如何獲取本地位置 javascript

var getLocation = function (successFunc, errorFunc) { //successFunc獲取定位成功回調函數,errorFunc獲取定位失敗回調
//首先設置默認內城市容
var defCity = {
id: '000001',
name: '北京市',
date: curDateTime()//獲取當前時間方法
};
//默認城市
$.cookie('VPIAO_MOBILE_DEFAULTCITY', JSON.stringify(defCity), { expires: 1, path: '/' });
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var lat = position.coords.latitude;

J. javascript 如何判斷本地路徑文件是否存在並打開

出於安全原因,瀏覽器不支持此類操作,至少現在不支持。以前IE是可以的,但後來修復了。

閱讀全文

與javascript本地路徑相關的資料

熱點內容
oppo如何開4g網路 瀏覽:267
java不安全 瀏覽:423
導入配置文件數據失敗 瀏覽:941
linux運行class 瀏覽:227
如何做好群管理員文件 瀏覽:979
linuxvim循環搜索文件 瀏覽:147
為什麼講女孩子更應該學習編程 瀏覽:742
雲數據備份不了了是怎麼回事 瀏覽:110
數據說話的股票有哪些股 瀏覽:612
一加照片保存在哪個文件夾 瀏覽:710
聯通省公司大數據 瀏覽:300
三星wifi管理員密碼 瀏覽:213
怎樣查看優盤正在被哪個文件使用 瀏覽:9
微信里傳的文件為什麼會過期 瀏覽:248
遇到不正規的網路平台怎麼辦 瀏覽:979
win10能裝天正嗎 瀏覽:105
小米2升級後怎麼恢復原狀 瀏覽:465
dnf90版本85史詩套 瀏覽:941
法蘭的dn是什麼數據 瀏覽:954
手機文件管理壓縮 瀏覽:7

友情鏈接