How do I set a page's base href in Javascript?

前端 未结 4 1232
清歌不尽
清歌不尽 2020-12-25 11:48

I want to set a page\'s base href attribute in Javascript based off of the current hostname. I have generated HTML pages that can be viewed on different hostnames, which mea

4条回答
  •  温柔的废话
    2020-12-25 12:30

    I think you'd better do it this way

        
    

    As location.hostname does not return the application context root! You could also log the document.location on the console console.log to see all available metadata on document.location.

提交回复
热议问题