Using hash plus querystring as binding for webpage loaded by jQuery?

Here is my situation. I have a webpage (not quite finished):

http://grapplingbasics.com/beta.php

I have a page slide for a specific div that puts a hash url in the url string. If a user links to this URL, he may be taken to that particular part of the page.

However, I would like them to hit this part of the page and upload a specific video with a single address.

It seems that you cannot put the query string and hash together like this: www.blah.com/index.php#BLAH?neat=one

I initially tried to turn the hash into part of the query, and then using split in jquery to assign it to a hash on the fly. However, the problem with this is that if I return false to the navigation, it will not show the query string in the URL bar, and if I do not return the false, then it will want to go to something that is not there!

What is the possible solution here?

+3
source share
2 answers

I created a small example for you that should explain how you can eliminate this.

 <script type="text/javascript">

    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }


    $(function () {
        $('a').click(function (event) {

            var thisHash = document.location.hash;

            $('body').animate({ scrollTop: $(thisHash).offset().top }, function () {
                if (getParameterByName('neat') != null) {
                    alert('I will play video ' + getParameterByName('neat'));
                }
            });
        });
    });

</script>

Html:

<a href='?neat=one#end'>Go</a>

<p id='end'>Imagine this is a panel you are going to in your example.</p>

In the above code, there is a getParameterByName function that scans your url to find pairs of query string values. and if its value is not null, it returns its value.

:... , - , , . . "", , .

+1

: www.blah.com/index.php?neat=one#BLAH

ben alman jquery bbq plugin: http://benalman.com/projects/jquery-bbq-plugin/

+1

All Articles