0

i want to create INTRO js to my website, when user first time visit my website. I use cookies with PHP. but its not worked.

This is my code

if(isset($_COOKIE["userip"]))
        {
            echo " $_COOKIE[userip]";
        }
        else
        {
            ?>
            <script>
            //I THINK THE PROBLEM IS AT THIS JS LINE
           // introJs();
            //javascript:introJs.start();
            introJs().setOption('showProgress', true).start();
            </script>
            <?php
            setcookie("userip", "mycookiename", time()+3600);
        }


<script type="text/javascript" src="intro.js"></script>

but if i put:

introJs().setOption('showProgress', true).start();

in body onload it is work. but what i need is checking cookies first.

pls help me

thank you

Peter
  • 10,492
  • 21
  • 82
  • 132
Def
  • 115
  • 1
  • 1
  • 14
  • Can you post the full php script properly – rahul patel Oct 05 '17 at 05:41
  • i think my problem not in PHP script, but how to call introJs() properly inside javascript. introJs(); OR javascript:introJs.start(); OR introJs().setOption('showProgress', true).start();....Thank you anyway – Def Oct 05 '17 at 05:44

2 Answers2

1

my problem is now fixed, i change javascript code like be like this:

      <script>
        $(document).ready(function(){
          javascript:introJs().setOption('showProgress', true).start();
        });
       </script>
Def
  • 115
  • 1
  • 1
  • 14
0

I think your issue is resolved by changing the order of scripts (or maybe adding a close tag to your first):

<!-- load intro.js FIRST -->
<script type="text/javascript" src="intro.js"></script>
<!-- use intro.js -->
<script>
  // include any options you want
  introJs().start();

  // set cookies if you want 
  // ...
</script>
bozdoz
  • 12,550
  • 7
  • 67
  • 96