1. JavaScript
การคัดลอกรหัสมีดังนี้:
-
* รับผู้อ้างอิงของคำขอ HTTP
* @ishost ว่าจะส่งคืนโฮสต์หรือไม่เมื่อผู้อ้างอิงบูลีนว่างเปล่า (ที่อยู่ของหน้าแรก)
-
ฟังก์ชั่น get_http_referer (ishost) {
if (ishost === ไม่ได้กำหนด) {ishost = true; -
if (document.referrer) {
ส่งคืน Document.referrer;
} อื่น {
ถ้า (ishost) {
ส่งคืน window.location.protocol + "//" + window.location.host;
} อื่น {
กลับ "";
-
-
-
2. C#
การคัดลอกรหัสมีดังนี้:
/// <summary>
/// รับผู้อ้างอิงคำขอ http
/// </summary>
/// <param name = "ishost"> ว่าจะส่งคืนโฮสต์เมื่อผู้อ้างอิงว่างเปล่า (ที่อยู่ของหน้าแรก) </param>
/// <return> สตริง </returns>
Public String GetReferer (Bool Ishost)
-
if (request.urlreferrer! = null)
-
return request.urlreferrer.toString ();
-
อื่น
-
ถ้า (ishost)
-
return request.url.scheme + ": //" + request.url.authority;
-
อื่น
-
กลับ "";
-
-
-
3. รับส่วนต่าง ๆ ของ URL คำขอใน C#
เว็บไซต์: http: // localhost: 1897/news/press/content.aspx/123? id = 1#toc
การคัดลอกรหัสมีดังนี้:
request.applicationPath/
request.physicalpathd: /projects/solution/web/news/press/content.aspx
System.io.path.getDirectoryName (request.physicalPath) d:/โครงการ/โซลูชัน/เว็บ/ข่าว/กด
request.physicalapplicationPathd:/โครงการ/โซลูชัน/เว็บ/
System.io.path.getFilename (request.physicalpath) เนื้อหา. aspx
request.currentExecutionFilePath/News/press/content.aspx
request.filepath/news/press/content.aspx
request.path/News/press/content.aspx/123
request.rawurl/news/press/content.aspx/123? id = 1
request.url.absolutepath/news/press/content.aspx/123
request.url.absoluteurihttp: // localhost: 1897/news/press/content.aspx/123? id = 1
request.url.schemehttp
request.url.hostlocalhost
request.url.port1897
request.url.authoritylocalhost: 1897
request.url.localpath/News/press/content.aspx/123
request.pathinfo/123
request.url.PathandQuery/News/press/content.aspx/123? id = 1
request.url.query? id = 1
request.url.fragment
request.url.segments/
ข่าว/
กด/
content.aspx/
123
4. หน้าต่าง JavaScript วัตถุตำแหน่ง
//www.vevb.com/article/57407.htm
แล้วล่ะ? คุณได้เรียนรู้ที่จะรับผู้อ้างอิงหน้าใน JavaScript และ C#หรือไม่? หากคุณมีคำถามใด ๆ โปรดติดต่อฉัน