I am trying to pass a has such as http://mysite.com/#32132 via JS to a custom function.
Here’s the function:
var downloadVideo = function(passed){
console.log(passed);
}
And here’s how I’m getting and passing the hash from the URL:
if(window.location.hash){
var hash = window.location.hash;
hash = hash.substring(1, hash.length); // Remove the # from the hash
setTimeout('downloadVideo('+hash+')', 3000)
}
After 3 seconds, I just get an error in the console:
Uncaught ReferenceError: 32132 is not defined
I’ve tried different ways of calling downloadVideo. With quotes, without quotes, without the plus signs. Nothing seems to work. If I console.log the hash var immediately before the setTimeout it displays it correctly.
You need to represent it as a string if there’s anything more than just numeric characters…
But better to pass a function that closes over
hash…