I’m using some 3rd party javascript to generate a slideshows within each of the posts on a blog. Each slideshow must have a unique ID to work properly. I figured the easiest way to do this would be to generate a large random number for each slideshow when it’s loaded on the page.
Below is a snippet of the relevant parts of the code where POSTID represents the random number. Note that the same random number must be referenced in the div below the script.
<script language="javascript" type="text/javascript">
$(function() {
$("#POSTID").webwidget_slideshow_dot({
slideshow_time_interval: '',
slideshow_window_width: '320',
slideshow_window_height: '480',
slideshow_title_color: '#17CCCC',
soldeshow_foreColor: '#000',
});
});
</script>
<div id="POSTID" class="webwidget_slideshow_dot">
<!-- some content goes here -->
</div>
Any help would be greatly appreciated!
Thanks
Math.random()produces a pseudo-random number in the range [0, 1).If you want a large integer, in the range [0, 999999], you can scale and round. For example,
will produce a pseudo-random integer in the range [0, 999999].
To attach your pseudo-random ID to the script, you might do:
Note that JavaScript’s
Math.random()does not produce unguessable numbers. As long as you are using it as a GUID generator within a web-page this is fine, but if you send your ID to the server, you should not rely on people not knowing it for security.