简体   繁体   中英

Moving up a directory with HTML from JS dom

This is my first time posting so any points would be nice about formatting or what not, but here's my problem anyway.

This is my JS Code

document.getElementById('mainnav-up').innerHTML =
"<div class='banner'>" +
"<a href='..\index.html'><div class='button'></div></a>" +
"</div>";

Which places a button on my HTML page under :

home/products/product1.html
<div id="mainnav-up"></div>

but instead of being taken to

home/index.html

I am instead taken to

home/products/..index.html

Which is non-existent. If I then hard code the link into the home/products/product1.html page it takes me to the index page correctly, but I'd like to be able to just edit one piece of code for the whole website.

Change

<a href='..\index.html'>

to

<a href='../product1.html'>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM