1

So, basically, I want people to be able to navigate my website, through links to Divs, but PREVENT the browser from changing the current URL (it adds #divname at the end of the .html file).

I have something like this:

<div id="modalLogin" class="modalLogin">
    <!-- random stuff here -->
</div>

And somewhere else I have a link to that Div:

<a href="#modalLogin"> 
    <img class="btnLogin" src="../images/btnLogin.png" alt="Log in!"/> 
</a>

But, as I mentioned before, whenever they click those kind of links, the URL changes. I'd like to be able to navigate the website WITHOUT that happening. If at all possible, using just HTML (no JavaScript, no jQuery, no AJAX).

While we're at it, I've seen entire websites not changing their URL at all (even when I've traced the requests and am clearly navigating through different files), and some don't even show you the 'expected address' (the URL on the bottom left of the browser). How do I do that?

Thanks in advance!

P.S.: I've searched this website, and apparently all 'similar' questions ask just about the opposite: how TO change the URL.

Franconstein
  • 145
  • 4
  • Why does it even matter if the URL changes? – OdraEncoded Jul 25 '14 at 06:27
  • I don't think it's possible using only HTML, the ``a`` tag stands for anchor point which is exactly what the browser looks for when appended with a ``#anchorPointName``. – Cosmin Pârvulescu Jul 25 '14 at 06:28
  • 2
    terrible idea. you are removing information your users and browser may need for no purpose other than what, some design preference of yours? You'll also ruin your SEO and your site wont work at all without JS. The technique you're asking for is called "cloaking" and it is universally considered bad practice unless you're writing malware. – SpliFF Jul 25 '14 at 06:28
  • You're asking for too much. Either do it with `JS`, either accept to have the URL that way. – Jerska Jul 25 '14 at 06:29
  • Dammit! I thought I might have been asking for too much. The reason I want this, is because I use modals - a lot. I don't want users going directly to a modal (either on purpose or by mistake). Edit: So, how is the non-HTML way of doing it (JS, or whatever)? – Franconstein Jul 25 '14 at 06:33
  • Also, I didn't know it was bad practice or seen as something bad. I thought it was actually better if people didn't get all those different 'websites' and just stayed on your 'home'. I'm sorry about that part! Just interested on the no #div thing only now! – Franconstein Jul 25 '14 at 06:36
  • For modals just show/hide a layer using javascript on `button` elements or divs with `onclick`. No need to use links at all. – SpliFF Jul 25 '14 at 06:36
  • Thanks SpliFF! Will dig into that right away! Thanks everyone else too! You've taught me some crucial stuff and responded really fast! Cheers! – Franconstein Jul 25 '14 at 06:39
  • @Franconstein if you still need JS approach: https://stackoverflow.com/a/1586379/1243247 – João Pimentel Ferreira Jan 05 '19 at 23:01
  • Possible duplicate of [How to remove the hash from window.location (URL) with JavaScript without page refresh?](https://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-url-with-javascript-without-page-r) – João Pimentel Ferreira Jan 06 '19 at 13:34

1 Answers1

0

I think You Can Use Javascript for This.

//Grab your current Url
var url = window.location.toString();
//Remove anchor from url using the split
url = url.split("#")[0];

SAMPLE JSFIDDLE

João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109