Hello i have a view (you can look at here: hidden link)
My view is not using ajax (because i would like to use amp in a while)
I would like redirect to a row when visitors click on submit button, so i basically want to add "&#myrow" to parameter url when they click on.
Not sure about what function to use.
Thanks!
Hello, unfortunately we don't have anything exactly like this built-in to the software. I think you could use custom JavaScript to detect whether or not the wpv_view_count URL parameter exists, and if so, append your hash to the URL. You could trigger any other code you want at that time as well, like animation to scroll to some specific row of results by ID.
Here's a handy utility function to get URL parameter(s) from a URL. You don't need to make any changes in this code:
var getParams = function (url) {
var params = {};
var parser = document.createElement('a');
parser.href = url;
var query = parser.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
params[pair[0]] = decodeURIComponent(pair[1]);
}
return params;
};
Reference: https://gomakethings.com/getting-all-query-string-values-from-a-url-with-vanilla-js/
Here's an example showing how to use the utility function to test whether or not the current page URL contains the parameter "wpv_view_count". You should be able to use this in the page load hook to determine if the search form has been submitted:
var params = getParams(window.location.href);
if( params['wpv_view_count'] && params['wpv_view_count'] == 5750 ) {
// You have confirmed the search form was submitted.
// Place custom code here to update the URL hash, scrollto the right location, etc.
}
Here's documentation for using location.hash to add something like #myrow in the URL:
https://www.w3schools.com/jsref/prop_loc_hash.asp
See "Set the anchor part" for an example.
My issue is resolved now. Thank you!