Search code examples
javascriptjqueryhashchange

disable hashchange


When you hover over a link on my site it displays the correct URL but once you click on it it adds a # which prevents the correct page from loading. How do I disable hashchange on my site:

http://www.ogormanconstruction.co.uk/

<script type='text/javascript' src="/wp-content/themes/child/scripts/jquery-1.6.2.min.js"></script>
<script type='text/javascript' src="/wp-content/themes/child/scripts/jMaster.js"></script>
<script type='text/javascript' src="/wp-content/themes/child/scripts/supersleight.plugin.js"></script>
<script type="text/javascript" src="/wp-content/themes/child/scripts/hashchange.js"></script>
<script type="text/javascript" src="/wp-content/themes/child/scripts/actions.js"></script>
<script type="text/javascript" src="/wp-content/themes/child/scripts/tinyscroll.js"></script>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
    theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>
</head>

<body <?php body_class(); ?>>

<div id="header">
            <ul id="nav">
                <li class="clearfix">
                    <div class="clearfix">
                        <div id="menuNav"><a href="javascript: void(0)" class="openNav">Menu</a></div>
                        <ul class='clearfix'><li><strong>O'Gorman Construction Ltd</strong><ul class='clearfix'><li><a href='/about-us'>About Us</a><li><a href='/contact'>Contact</a></li></li><li><a href='/work'>Work</a></li><li><a href='/recruitment'>Recruitment</a></li></ul></li><li><strong>Services</strong><ul class='clearfix'><li><a href='/site-logistics'>Labour Supply</a></li><li><a href='/waste-management'>Drainage</a></li><li><a href='/security-services'>Fencing</a></li><li><a href='/traffic-management'>Demolition</a></li></ul></li><li><strong>&nbsp;</strong><ul><li><a href='/multi-service-gangs'>Ground Works</a></li><li><a href='/facilities-accomodation'>Multiservice Gangs</a></li><li><a href='/small-works-maintenance'>Engineering</a></li><li><a href='/catering-services'>Water Treatment</a></li></ul></li></ul>
                    </div>
                    </div>
                </li>
            </ul>
            <a href="/" id="logo"></a>
        </div>

<h2>Work</h2>
<div class="leftCol">
<div class="rightCol gallery">
    <ul id="homeGallery">
<li id="prevControl"><a href="#">Previous</a></li>
        <li id="galleryItems">

                    <ul>

                    <li>
                        <div class="galleryImage"><img src='/wp-content/themes/child/images/1.jpg' /></div>
                        <div class="galleryText"><div class="leftCol noborder" style="text-align: left;"><strong>Project I</strong></div></div>
                    </li>

                    <li>
                        <div class="galleryImage"><img src='/wp-content/themes/child/images/2.jpg' /></div>
                        <div class="galleryText"><div class="leftCol noborder" style="text-align: left;"><strong>Project II</strong></div></div>
                    </li>

                    <li>
                        <div class="galleryImage"><img src='/wp-content/themes/child/images/4.jpg' /></div>
                        <div class="galleryText"><div class="leftCol noborder" style="text-align: left;"><strong>Project III</strong></div></div>
                    </li>

                    </ul>

        </li>

<li id="nextControl"><a href="#">Next</a></li>
        <li id="copyright">&copy; O'Gorman Construction Ltd</li>
    </ul>
</div>
</div>


    <div id="main">

I think the bit I need to edit is within actions.js but I'm not sure what I need to change

    $(window).hashchange();
});

function runSetups() {
    interceptLinks();
    setupHomeGallery();
    setupProjects();
    setupProject();
    setupNews();
    setupBackToTop();
    setupStickies();
}

function setupWindowEvents() {
    $(window).scroll(checkScrolling);

    $(window).hashchange(function () {
        var hash = location.hash;

        loadContent(hash.substr(1));
    });

    $(document).mousemove(function (event) {
        var mx = event.pageX;
        var my = event.pageY;

        if ($('#menuNav.open').length > 0) {
            if (my > $('#header').outerHeight() + 70) {
                $('#menuNav .closeNav').trigger('click');
                $('#menuNav').removeClass('open');
            }
        }
    });

Solution

  • your problem lies not in what your script.js but in your action.js where your href is being loaded into this function loadContent(url). Your href would then be converted into a hash link with the location.hash. You have a few choices here.. you could either delete that function if you are not using it, change the location.hash to window.location or just change you href by omitting the '/'.

    It really depends on what you want to do.