Window.location.hash help needed with syntax
Asked Answered
S

5

7

My website is available at http://visualise.ca/ and when you load a post by clicking a thumbnail it will loads the post within the page using ajax. When you close the post it uses this code in order to change the url back to http://visualise.ca/ without reloading the page:

$("#close").live("click", function(event) {
    $("#board").fadeOut("slow");
    $("#board-wrapper").slideUp("slow");
    $("html,body").delay(1000).animate({scrollTop: 0}, 300);
    window.location.hash = "";
    window.history.pushState(null,null,site_url+"/");
    return false;
});

but in IE8 it changes it back to http://visualise.ca/# instead of http://visualise.ca/. Is there a way to correct this and make sure it is changed to http://visualise.ca/ ?

Syphilology answered 25/8, 2011 at 20:46 Comment(1)
IE8 does not support the html5 history API, consider using a fallback like github.com/balupton/history.jsRecognize
T
1

I happen to be doing a lot of ajax history lately. I am trying my own implementation where I navigate through pages and modals and back and fourth. Making very good progress.

Since the beginning of the tests I have noticed that the root hash; ONCE CHANGED back to the initial page (where it all started) it, only loses the hash (#) if it was a BROWSER BACK button click. If I change the hash back to '', it will ALWAYS show the /# at the end.

As far as IE8 is concerned, I don't believe there is any solution but using the iFrame hack and, since I have not got around to test IE8/iframe hack yet, I cannot comment on it.

For my solution I am using a mix of hash and pure command control. I should have the final version fully tested within a couple of weeks (wishful thinking).

Besides, who cares if a hash/sharp is left at the end of the url. I NEVER LOOK AT THE URL once I hit a web site; I just look at the contents of the page. REALLY: it just hit me that the url is only important when I want to copy and paste it. Other than that, I NEVER look at it.

Turbinal answered 7/11, 2011 at 22:35 Comment(0)
I
3

Wouldn't this stop it?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
    $(document).ready(function() {    
    $(".testPhoto").click(function(event){
        event.stopPropagation();
        alert("do something");
        return false;
    });  
});
</script>
<a class="testPhoto" href="#testPhoto" onclick="testPhoto">Test Photo</a>
Indistinguishable answered 16/10, 2011 at 16:6 Comment(0)
V
1

Anything less that IE9 will reload the page without the ending Hash#. My suggestion is to check for IE and remove or blank out the content. If you do want the exact way, you'll have to dodge some IE Quirks.

 if ( jQuery.browser.msie && ( parseInt( jQuery.browser.version ) < 9 ) ) {
     window.location = 'http://visualise.ca";
     document.execCommand( 'stop' );
 }
Vocational answered 7/11, 2011 at 22:16 Comment(0)
T
1

I happen to be doing a lot of ajax history lately. I am trying my own implementation where I navigate through pages and modals and back and fourth. Making very good progress.

Since the beginning of the tests I have noticed that the root hash; ONCE CHANGED back to the initial page (where it all started) it, only loses the hash (#) if it was a BROWSER BACK button click. If I change the hash back to '', it will ALWAYS show the /# at the end.

As far as IE8 is concerned, I don't believe there is any solution but using the iFrame hack and, since I have not got around to test IE8/iframe hack yet, I cannot comment on it.

For my solution I am using a mix of hash and pure command control. I should have the final version fully tested within a couple of weeks (wishful thinking).

Besides, who cares if a hash/sharp is left at the end of the url. I NEVER LOOK AT THE URL once I hit a web site; I just look at the contents of the page. REALLY: it just hit me that the url is only important when I want to copy and paste it. Other than that, I NEVER look at it.

Turbinal answered 7/11, 2011 at 22:35 Comment(0)
C
0
window.location = window.location.href.replace( /#.*/, "");

This will work for IE.

Chartography answered 26/8, 2011 at 10:36 Comment(1)
This reloads the page. It must not. ;-)Syphilology
R
0
$('#close').click(function(){

window.location = "http://visualise.ca/";

});
Repel answered 12/10, 2011 at 0:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.