0

I am working on a slide show where I need to return a portion of HTML with a <script> tag and a piece of javascript function in it.I want to add it as I can have multiple slide shows and each one with different properties like transitions,slide speed etc.This function consists the parameters of the slider properties.

  return    '<div id="slider" class="nivoSlider">'+
                '<div class="">'+
                    '<img id="" class="image mover" style="position:absolute;left:0px;top:0px;" src="http://localhost/gobiggi_VS_2_2/images/slideShow/slide01.jpg" data-thumb="images/slideShow/thumb/slide01.jpg" alt="" />'+
                '</div>'+
                '<div class="">'+
                    '<img id="" class="image mover" style="position:absolute;left:0px;top:0px;" src="http://localhost/gobiggi_VS_2_2/images/slideShow/slide02.jpg" data-thumb="images/slideShow/thumb/slide02.jpg" alt="" />'+
                '</div>'+
                '<div class="">'+
                    '<img id="" class="image mover" style="position:absolute;left:0px;top:0px;" src="http://localhost/gobiggi_VS_2_2/images/slideShow/slide03.jpg" data-thumb="images/slideShow/thumb/slide03.jpg" alt="" />'+
                '</div>'+
                '<div class="">'+
                    '<img id="" class="image mover" style="position:absolute;left:0px;top:0px;" src="http://localhost/gobiggi_VS_2_2/images/slideShow/slide04.jpg" data-thumb="images/slideShow/thumb/slide04.jpg" alt="" />'+
                '</div>'+
            '</div>'+'<script>$("#slider").nivoSlider({effect: "sliceDown",animSpeed: 500,pauseTime: 3000,startSlide: 0,controlNavThumbs: true,controlNavThumbsFromRel:true, pauseOnHover: true,manualAdvance: false});</script>';

The function inside setTimeout is the one I need to store inside the HTML I tried to achieve it by storing it in a variable and attaching it inside the setTimeout().I used .toString() and .append() .html .text but the script directly runs or executes instead of storing it in the html structure.How can I just store the function inside the script tag in the HTML structure?

3
  • setTimeout() doesn't wait for other code. If code is not done yet, or has a bit of delay the code can collide. Commented Mar 7, 2013 at 10:03
  • jQuery evaluates any script tags in your HTML, then discard them. Commented Mar 7, 2013 at 11:09
  • @SalmanA Can you suggest a way how can I store it to the HTML as I need to execute the function once the user publishes his website. **FYI:**I want it to be stored along with the html to the database,becoz this is a website builder kind of application.User can save and publish it on the web,so after publish I need to have the function or properties stored somewhere in the html structure so that the slideshow works.And each instance of slideshow may have different parameters set against it,so I cannot have a common <script> tag in the page Commented Mar 7, 2013 at 11:17

2 Answers 2

1

If you want the contents of the script tag to be stored as a function, you need to give that function a name. Simply enclose it all in a function setSlideShowTimeout() { setTimeout(function … ); };

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the prompt response.setTimeoutwas added for testing.What we are trying is to save the entire <script> tag with the function properties in the html and have it saved to the database.**EDITED the question for it.Please have a look**
the id #slider would be attached dynamically for each slider
1

your setTimeout function is incorrect..

 '<script>setTimeout(function slideShow(){$("#slider")......</script>';
                      //------^^^^^^^^---here you are creating a function `slideShow`

it should be

'<script>setTimeout(function(){$("#slider")......</script>';

OR

 function slideShow(){
      $("#slider").nivoSlider({
            effect: "sliceDown",
            animSpeed: 500,
            pauseTime: 3000,
            startSlide: 0,
            controlNavThumbs: true,
            controlNavThumbsFromRel:true, 
            pauseOnHover: true,
            manualAdvance: false
      })
  }

 setTimeout(slideShow,100);

and i don't think you need to add this in return.. add this in your main page.. and it should work

6 Comments

setTimeoutwas added for testing.What we are trying is to save the entire <script> tag with the function properties in the html and have it saved to the database.**EDITED the question for it.Please have a look**
the id #slider would be attached dynamically for each slider.
There is nothing wrong with using a name with a function expression, it's optional (though usually omitted).
why don't you store the script in another div without the <script> tag , with display:none, give it an id... and take it out when need....have you tried that too ??
I want it to be stored along with the html to the database,becoz this is a website builder kind of application.User can save and publish it on the web,so after publish I need to have the function or properties stored somewhere in the html structure so that the slideshow works.And each instance of slideshow may have different parameters set against it,so I cannot have a common <script> tag in the page
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.