Javascript Image Slider / Posts /

Display a particular slide that is specified in the current URL

13

How to select a particular slide with an outside call like
< a href="slider.html?Page=5">
I tried using <body onload='mydisplay();'>
function mydisplay(){
    var str = location.search;
    var n =str.indexOf('=')+1;
    var indx=str.substring(n);
    imageSlider.displaySlide(indx, true, true);
}
This often produce errors and messes up the sequence

Thank you for your time - alberto

Alberto  10 years ago   viewed: 18725    

2 Answers

8

You are almost there. It will work if the indx is an integer instead of string. You also need to make sure the indx is less than the total number of the slides as it is zero-based:

<!DOCTYPE html> <html> <head> ...... <script src="themes/66/js-image-slider.js" type="text/javascript"></script> <script> function mydisplay() { var str = location.search; var n = str.indexOf('=') + 1; var indx = str.substring(n); try { if (indx) indx = parseInt(indx); imageSlider.displaySlide(indx, true, true); } catch (e) { } } </script> </head> <body> ... ... <!--put the following script at the end of the body, just before </body>--> <script>mydisplay();</script> </body> </html>
Milo   10 years ago
0
Hi, Milo it works very well!! Grazie e mille - alberto
Alberto   10 years ago

   

Your name*
Password
(Optional. Used to modify this post afterwords)
+ =  

Ask your Own Question

  • If your question is related to the topic of this post, you can post your question to this page by clicking the "Post a reply" button at left;

  • When you want to start a new page for your question: