この記事では、現在のURLとソースURLを取得するJS実装方法について説明します。次のように、参照のために共有してください。
index.html:
<!doctype html> <html lang = "zh-cn"> <head> <meta charset = "utf-8"> <meta name = "viewport" content = "width、width =" width = 1、maximing-scale = 1、user-scalable = no "> <titlate> <title> <title> href = "demo.html"> link </a> </body> </html>
demo.html:
<!doctype html> <html lang = "zh-cn"> <head> <meta charset = "utf-8"> <meta name = "viewport" content = "width、inivery-width = 1、maximing-scale = 1、user-scalable = no"> <titpint> new H5テンプレート< style = "width:300px;" name = "nowurl" id = "nowurl"> <br> source url:<input type = "text" style = "width:300px;" name = "fromurl" id = "fromurl"> <script> var nowurl = document.url; var fromurl = document.referrer; document.getElementById( 'nowurl')。value = nowurl; document.getElementById( 'fromurl')。value = fromurl; </script> </body> </html>
複製画像:
それが//www.vevb.com/index.html経由で入っていると仮定します
それで:
現在のurl://www.vevb.com/demo.htmlを取得します
ソースを取得するためのURLは://www.vevb.com/index.htmlです
説明:
document.urlプロパティは、現在のドキュメントのURLを返します。
document.referrerプロパティは、現在のドキュメントをロードするドキュメントのURLを返します。
JavaScript関連のコンテンツの詳細については、このサイトのトピックをご覧ください:「JavaScript検索アルゴリズムスキルの要約」、「JavaScriptデータ構造とアルゴリズムスキルの概要」、「JavaScriptトラバーサルアルゴリズムとテクニックの要約」、「JSON操作の概要」の概要「JavaScriptトラバーサルアルゴリズムと技術の要約」 JavaScriptアニメーション効果とテクニック "、「JavaScriptエラーとデバッグテクニックの要約」および「JavaScriptの数学操作の使用法の要約」
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。