0

Sharepoint offers the following JavaScript function to get a QueryString parameter value:

GetUrlKeyValue('a', false, 'www.example.com?a=test')

I would like to know if there is a similar JavaScript function to get a parameter value from within inplview.js API hashed url like the following:

http://www.example.com/testsite/Lists/SampleList/List.asp#InplviewHash7ed4366a-8857-4c61-b92f-6d6f635ad420=WebPartID%3D%7B38A3E939--9187--4C4A--BF28--0CEF3988314A%7D-FilterField1%3DFoo-FilterValue1%3DBar

From the previous URL, I would like to extract 'FilterField1' and 'FilterValue1' values ('Foo' and 'Bar' respectively), as if those were regular QueryString parameters.

  • JavaScript does not offer any function to get query string parameters. But you can create your custom function to get query string parameters. – Bharat Khunti Mar 31 '18 at 17:09
1

I didn't find a built in function to achieveing this. So I wrote a very simple function to get what I need.

I post this as an answer but I'm still open to suggestions.

Thank you.

function GetUrlHashKeyValue(key) {
    var value = '',
        hash = window.location.hash,
        fv1Index = hash.indexOf(key + '%3D');

    if (fv1Index != -1) {

        value = hash.substr(fv1Index + key.length + 3);

        // value could end at the end of the string, or when another value comes right after
        // One dash "-" found means another parameter follows, only if it is not followed by another dash "--"
        // Double dash "--" is one dash escaped within a string.
        value = value.replace(/--/g, '||');

        // Now, if we find a single dash "-", it is delimiting a new parameter
        var dashFoundAt = value.indexOf('-');
        if (dashFoundAt != -1) {
            value = value.substring(0, dashFoundAt);
        }

        // Rollback our custom double dash escaping
        value = value.replace(/\|\|/g, '--');
    }

    return value;
}

var filterVal = GetUrlHashKeyValue('FilterValue1');

You might need to decode the result:

decodeURIComponent(filterVal);
0

See the second answer here: https://stackoverflow.com/questions/3552944/how-to-get-the-anchor-from-the-url-using-jquery

Or do a search for "javascript read anchor".

  • Thank you. I know I can get the entire anchor from the URL, I just wanted to know if there is any built in function for parsing querystring-like parameters built in the anchor parameter when using inplview.js in Sharepoint. – zed Apr 3 '18 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.