Stephen
Stephen

Reputation: 137

script hash value, loss of one alphanumeric character

I had to rename all of my .html files to .php so that I can use php gzip compression. Anyway the switch has broken one of my scripts. It's a script that loads in and animates content. It grabs the content from various pages and loads it into a container. That part of the script works fine.

When using the .html extension, the script will happily append the page being viewed to the URL, as in: www.site.com/#ABOUT

But now that I've renamed everything from .html to .php, there's always a missing letter, as in: www.site.com/#ABOU <--- missing a 'T'

Or, www.site.com/#CONTAC <--- missing a 'T'

www.site.com/#NEWSLETTE <--- missing an 'R'

Here's the part of the script that does this append function:

var hash = window.location.hash.substr(1);
var href = $('#nav li a').each(function(){
    var href = $(this).attr('href');
    if(hash==href.substr(0,href.length-5)){
        var toLoad = hash+'.php #content';  <--- .php (was: .html)
        $('#content').load(toLoad)
    }                                           
});

What's up with this?

Upvotes: 0

Views: 81

Answers (3)

Bergi
Bergi

Reputation: 664650

If href.substr(0,href.length-5) was intended to remove .html, you might need to change it to href.substr(0,href.length-4) so it removes .php.

Upvotes: 0

jncraton
jncraton

Reputation: 9132

I'm not going to say this is the right way to do it, but changing this should work:

if(hash==href.substr(0,href.length-4)){
    var toLoad = hash+'.php #content';  <--- .php (was: .html)
    $('#content').load(toLoad)
}      

Upvotes: 1

Farzher
Farzher

Reputation: 14573

href.substr(0,href.length-5)

Since your switch from .html to .php, you want

href.substr(0,href.length-4)

.php is 1 character shorter than .html

Upvotes: 3

Related Questions