0

In my HTML, I am currently using the following BASE tag to simplify file management:

<base href="../" target="_blank" />

I am willing to add a 'top of the page' button at the bottom of a page. The following line will not work, probably because the base is one directory up.

<a id="back2top" class="button" href="#">Back to the top</a>

So I tried this instead (where the href points to the page itself):

<a id="back2top" class="button" href="fr/1_calendar.html">Back to the top</a>

However, when I click on the button, the bowser does 2 things:
- it goes to the top of the page (what I want)
- and opens a new window (tested on IE and Chrome).

Is there a way I can:
- either override BASE so that href="#" works
- or prevent the second window from opening

tos
  • 966
  • 1
  • 9
  • 20
  • It seems that the `` does more harm than good here. Can't you get rid of it? Anyway, the new window problem can be solved without Javascript by using `target=_top` in the "top of page" link. – Mr Lister Feb 02 '12 at 19:31
  • Here is an interesting discussion on the pros and cons of using base: http://stackoverflow.com/questions/1889076/is-it-recommended-to-use-the-base-html-tag – skybondsor Feb 02 '12 at 19:31
  • Thanks for these interesting comments. I'm going to try to get rid of the base. But in my case it is a good way to keep a common "images" directory along with multiple directories containing the pages themselves: "website_en", "website_fr", etc. – tos Feb 03 '12 at 08:50

2 Answers2

0

If you can use javascript this would work:

function goToTop(){
    window.scrollTo(0,0)
    return false; //prevent page from reloading
}

Your html could look like:

<a href="javascript:goToTop()">Back to the top</a>

or:

<a onclick="javascript:goToTop()">Back to the top</a>
Chris Sobolewski
  • 12,363
  • 12
  • 56
  • 95
0

If you use <base href=...>, it by definition affects all relative URLs. It cannot be overridden; the only way to prevent it from affecting a URL is to use a relative URL.

So if <base href=...> is used, the only way in HTML to set up a link to the start of a document is to use one with a href specifying the absolute (full) URL of the document itself.

On the other hand, by the spec the href value in base tag must be an absolute URL. So whatever the tag does in your case is to be classified as undocumented error handling.

Jukka K. Korpela
  • 178,198
  • 33
  • 241
  • 350
  • I get it. About the relative href, I knew about it, but I am running in a controlled environment. The mini-site is the help section of an android app. I'll try to find a better way, for the sake of stability. – tos Feb 03 '12 at 08:47