JavaScript獲得頁面base標(biāo)簽中url的方法

字號:


    如果網(wǎng)頁中定義了base標(biāo)簽,我們可以通過js代碼獲得base的url地址
    <!DOCTYPE html>
    <html>
    <head>
    <base id="htmldom" href="">
    </head>
    <body>
    <p>Base URL is:
    <script>
    document.write(document.getElementById("htmldom").href);
    </script>
    </p>
    </body>
    </html>
    運(yùn)行結(jié)果如下:
    Base URL is:http://www.ynpxrz.com/