当前位置:首页 > Web开发 > 正文

4、location.port 返回 web 主机的端口 !DOCTYPE htmlhtmlheadmeta char

2024-03-31 Web开发

1、location.href:返回当前页面的URL

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> document.write("当前页面的URL:"); document.write(location.href); </script> </body> </html>

技术图片

2、location.hostname:返回WEB主机的域名

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> document.write("WEB主机的域名:"); document.write(location.hostname); </script> </body> </html>

技术图片

3、location.pathname 返回当前页面的路径和文件名

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> document.write("当前页面的路径和文件名"); document.write(location.pathname); </script> </body> </html>

技术图片

有中文乱码现象。

4、location.port 返回 web 主机的端口

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> document.write("web 主机的端口 "); document.write(location.port); </script> </body> </html>

技术图片

5、location.protocol 返回所使用的 web 协议

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> document.write("使用的 web 协议:"); document.write(location.protocol); </script> </body> </html>

技术图片

JS——BOM(Locate东西)

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31176.html