Javascript Get Website URL

后端 未结 7 1979
别那么骄傲
别那么骄傲 2020-12-29 05:37

How do I get Javascript to tell me the website url.

For example if I have a page www.example.com/page.html

I want Javascript to tell me the site

相关标签:
7条回答
  • 2020-12-29 06:33

    use

    document.location.origin+document.location.pathname;
    

    where document.location.origin will redirect you to "http://www" and document.location.pathname will redirect you to "/stackoverflow/"(Name of your project). In this way you can give reference to page or post you want in your js file.Suppose if i want reference to my home page i would have use

    var address=document.location.origin+document.location.pathname;
     window.location.replace(address+"/home");
    

    So using above example i can easily redirect to my homepage

    0 讨论(0)
提交回复
热议问题