Learning Path

'/'and'./'and '../'

Posted by Riino on October 14, 2020 computer web path router


Generally we use ‘path’ in web or in file system, to aim a target where we want to navigate. The format, sometimes is confusing, when we are using changeable base_url.

For example, when this jekyll blog runs in local, the base_url is localhost, while it is riino.site now. In other cases, the situation might be more complex. For example, in dev env, the base_url is example.com, while in prod env, it become example.com/welcome!

When we handle this, the final method is

location.href='example.html' //with history


location.replace('example.html') //without history

Of course, we can also use other ‘location’ to navigate from different source:

self.location.href;//Current page
window.location.href;//Current page
this.location.href;//Current page
location.href;// Current page
parent.location.href;//Parent page
top.location.href;//Top page       

However, how can we manage the format of path?

Download Playground html

Click to download this playground html file :