Basic replace html tag

696E20727569

Junior Member
Joined
Feb 25, 2015
Messages
9
Reaction score
0
Hi, I'm trying to figure how it works to do a replace in html tag before I learn how to replace html hash tag..
I am aiming to work on futher -stackoverflow.com/questions/269044/remove-fragment-in-url-with-javascript-w-out-causing-page-reload

So I could not get my basic to replace the tag on the address bar.. please guide..
HTML:
<head>
<script>
function myFunction(){
var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
}
</script>
</head>
<body onload="myFunction()">
</body>

The actual stuff is that I wanna work on #replacement if anyone knows this. Please share:
Code:
<script>
window.location.replace("#");
// slice off the remaining '#' in HTML5:    
if (typeof window.history.replaceState == 'function') {
  history.replaceState({}, '', window.location.href.slice(0, -1));
}
</script>
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
Hi, I'm trying to figure how it works to do a replace in html tag before I learn how to replace html hash tag..
I am aiming to work on futher -stackoverflow.com/questions/269044/remove-fragment-in-url-with-javascript-w-out-causing-page-reload

So I could not get my basic to replace the tag on the address bar.. please guide..
HTML:
<head>
<script>
function myFunction(){
var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
}
</script>
</head>
<body onload="myFunction()">
</body>

The actual stuff is that I wanna work on #replacement if anyone knows this. Please share:
Code:
<script>
window.location.replace("#");
// slice off the remaining '#' in HTML5:    
if (typeof window.history.replaceState == 'function') {
  history.replaceState({}, '', window.location.href.slice(0, -1));
}
</script>

Code:
//a more flexible replacement using regex
window.location.href.replace(/#[^?&]*/, '');
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top