Creating a new Location object in javascript

后端 未结 4 1531
夕颜
夕颜 2020-11-27 12:50

Is it possible to create a new Location object in javascript? I have a url as a string and I would like to leverage what javascript already provides to gain access to the di

4条回答
  •  情话喂你
    2020-11-27 13:35

    You can leverage the power of an anchor element

    var aLink = document.createElement("a");
    aLink.href="http://www.example.com/foo/bar.html?q=123#asdf";
    alert(aLink.pathname);
    

提交回复
热议问题