JavaScript获得页面base标签中url的方法


本文实例讲述了JavaScript获得页面base标签中url的方法。分享给大家供大家参考。具体如下:

如果网页中定义了base标签,我们可以通过js代码获得base的url地址

<!DOCTYPE html>
<html>
<head>
<base id="htmldom" href="http://www.phpstudy.net/">
</head>
<body>
<p>Base URL is:
<script>
document.write(document.getElementById("htmldom").href);
</script>
</p>
</body>
</html>

运行结果如下:

Base URL is:http://www.phpstudy.net/

希望本文所述对大家的javascript程序设计有所帮助。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3