HTML : Specify a default URL and a default target for all links on a page

The HTML <base> element specifies the base URL to use for all relative URLs in a document. There can be only one <base> element in a document.

Full information at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

Rou…


This content originally appeared on DEV Community and was authored by Rajesh Kumar Yadav

The HTML <base> element specifies the base URL to use for all relative URLs in a document. There can be only one <base> element in a document.

Full information at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

Routing or URL rewriting with base tag

Let's say you are located at:

www.domain.com/folder/subfolder/

Now if in your index.html file, you have the anchor tag to redirect to test.html as -

<a href="test.html">Click here</a>

Then this anchor will be regular anchor and will leads to

www.domain.com/folder/subfolder/test.html

Now if you will add base tag in your index.html's head tag as -

<base href="http://www.domain.com/" />

Then your same anchor

<a href="test.html">Click here</a>

now will lead to

www.domain.com/test.html

Buy Me A Coffee

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on LinkedIn and Twitter.


This content originally appeared on DEV Community and was authored by Rajesh Kumar Yadav


Print Share Comment Cite Upload Translate Updates
APA

Rajesh Kumar Yadav | Sciencx (2021-05-27T07:11:02+00:00) HTML : Specify a default URL and a default target for all links on a page. Retrieved from https://www.scien.cx/2021/05/27/html-specify-a-default-url-and-a-default-target-for-all-links-on-a-page/

MLA
" » HTML : Specify a default URL and a default target for all links on a page." Rajesh Kumar Yadav | Sciencx - Thursday May 27, 2021, https://www.scien.cx/2021/05/27/html-specify-a-default-url-and-a-default-target-for-all-links-on-a-page/
HARVARD
Rajesh Kumar Yadav | Sciencx Thursday May 27, 2021 » HTML : Specify a default URL and a default target for all links on a page., viewed ,<https://www.scien.cx/2021/05/27/html-specify-a-default-url-and-a-default-target-for-all-links-on-a-page/>
VANCOUVER
Rajesh Kumar Yadav | Sciencx - » HTML : Specify a default URL and a default target for all links on a page. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/27/html-specify-a-default-url-and-a-default-target-for-all-links-on-a-page/
CHICAGO
" » HTML : Specify a default URL and a default target for all links on a page." Rajesh Kumar Yadav | Sciencx - Accessed . https://www.scien.cx/2021/05/27/html-specify-a-default-url-and-a-default-target-for-all-links-on-a-page/
IEEE
" » HTML : Specify a default URL and a default target for all links on a page." Rajesh Kumar Yadav | Sciencx [Online]. Available: https://www.scien.cx/2021/05/27/html-specify-a-default-url-and-a-default-target-for-all-links-on-a-page/. [Accessed: ]
rf:citation
» HTML : Specify a default URL and a default target for all links on a page | Rajesh Kumar Yadav | Sciencx | https://www.scien.cx/2021/05/27/html-specify-a-default-url-and-a-default-target-for-all-links-on-a-page/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.