小码哥的IT人生

HTML DOM protocol 属性

JavaScript基础 2022-06-08 12:15:05小码哥的IT人生shichen

HTML DOM protocol 属性

定义和用法

protocol 属性是一个可读可写的字符串,可设置或返回当前 URL 的协议。

语法

location.protocol=path

实例

假设当前的 URL 是: http://example.com:1234/test.htm#part2:

<html>
<body>
<script type="text/javascript">
document.write(location.protocol);
</script>
</body>
</html>

输出:

http:

TIY

完整实例【使用 location 对象的 protocol 属性】:

<html>
<body>
<script type="text/javascript">
alert(location.protocol)
</script>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024