Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing # fragment identifier from address bar

Hi i hope someone can help. i want to hide the fragment identifier from the address bar so instead of:

www.mydomain.com/example.html#something

i just get:

www.mydomain.com/example.html

when i click on an anchor tag.

I have looked at lots of related questions and forums but still can't quite figure it out. I'm pretty sure i should be using something along the lines of:

window.location.href.replace(/#.*/,''); //and or .hash

put just cannot figure it out.

localScroll plugin allows you to hide or keep the identifiers and by default they are hidden. i think many gallery plugins have a similar option too.

but when i try and do it myself (bit of a novice) i get crazy to no results.

below is some basic example script i would like it to work with:

<style>
.wrap{
width:300px;
height:200px;
margin:auto;
}

.box{
width:300px;
height:200px;
position:absolute;
display:none;
}

#one{background:red;}
#two{background:blue;}
#three{background:green;}

.load{display:block;}
</style>


<body>
<ul>
    <li><a href="#one">One</a></li>
    <li><a href="#two">Two</a></li>
    <li><a href="#three">Three</a></li>
</ul>

<div class="wrap">
    <div id="one" class="box load">This is Box 1</div>
    <div id="two" class="box">This is Box 2</div>
    <div id="three" class="box">This is Box 3</div>
</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(document).ready(function() {

$("ul li a").click(function(){

       $("div.box").fadeOut(1000);

       $($(this).attr('href')).fadeIn(1000);

    });
});
</script>
</body>
like image 839
thom Avatar asked Feb 02 '11 08:02

thom


People also ask

What is the synonym of removing?

verbexpel from place or situation. ban. cast out. deport. discard.

What does it mean by removing?

verb (used with object), re·moved, re·mov·ing. to move from a place or position; take away or off: to remove the napkins from the table. to take off or shed (an article of clothing): to remove one's jacket. to move or shift to another place or position; transfer: She removed the painting to another wall.

What is the verb for remove?

verb. re·​move | \ ri-ˈmüv \ removed; removing.

How do you use removal in a sentence?

1 They demanded her removal from office. 2 The removal of petty restrictions has made life easier. 3 Clearance of the site required the removal of a number of trees. 4 Allegations of abuse led to the removal of several children from their families.


1 Answers

Add

return false;

at the end of your click function, it will stop this event propagation

like image 189
Riccardo Galli Avatar answered Nov 16 '22 02:11

Riccardo Galli