-6

I need for delaying opening of a popup. This is the code of my popup:

<script type="text/javascript">
var pmauid = 'Numbers';
var pmawid = 'Numbers';
var fq = '0';
</script>
<script type="text/javascript" src="http://mypopnetwork.com"></script>

So, I need for apply a delay in this part of code:

<script type="text/javascript" src="http://mypopnetwork.com"></script>

If I editing in this way, nothing happened:

<script type="text/javascript" window.setTimeout() src="http://mypopnetwork.com"></script>

Maybe I wrong syntax. This popup is normally open after clicking on an alertbox.

I tried also in this way:

setTimeout(function () {
    <script type="text/javascript" src="http://mypopnetwork.com"></script>;
}, 5000);
GDaquila
  • 131
  • 2
  • 11
  • 2
    You cannot just inject JavaScript into HTML and expect it to magically work. You could dynamically load the script instead and defer the loading as long as you want. – Felix Kling Sep 28 '15 at 22:07
  • Mmm How I can do this? – GDaquila Sep 28 '15 at 22:09
  • Quick search leads me to this link: http://www.w3schools.com/jsref/met_win_settimeout.asp - have you ever tried to find a solution first by yourself? – colidyre Sep 28 '15 at 22:10
  • See [Include a JavaScript file in another JavaScript file?](http://stackoverflow.com/q/950087/218196). – Felix Kling Sep 28 '15 at 22:10
  • Yes, I tried this: http://www.w3schools.com/jsref/met_win_settimeout.asp But not works. I need for apply a delay in my popup code. Example: 1 popup start in 4 seconds after I click on button of alertbox. – GDaquila Sep 28 '15 at 22:17
  • I can use JQuery for load the script in this way: $.getScript("my_lovely_script.js", function(){ alert("Script loaded but not necessarily executed."); }); And simply apply a delay? – GDaquila Sep 28 '15 at 22:20
  • why are you loading a script via jQuery? Plus that code does not look like a popup. – James Parsons Sep 28 '15 at 22:46
  • it was a simply question, I haven't try with JQuery. The complete code of my popup is this – GDaquila Sep 28 '15 at 22:47

1 Answers1

0

For one, you are treating JavaScript as if it were some sort of attribute, It should be in between the <script> tags (if your doing it inline) like:

<script>
    // your code here
</script> 

or if you want to reference a JavaScript file:

<script src="./whatever.js"></script>

or

<script src="http://foo.com/script.js"></script>

Second off, you need to provide a callback and a timeout length to setTimeout(). So in the end, you code should look like:

setTimeout(function () {
    alert("whatever");
}, 5000);

Where the callback is what you want to fire after the timer and 500 is the delay in milliseconds.

James Parsons
  • 6,097
  • 12
  • 68
  • 108
  • The problem is: I have 2 popups, I need for add a delay in them code. I tried also with setTimeout(function () { ; //my pop code }, 5000); – GDaquila Sep 28 '15 at 22:15
  • and what is your issue? – James Parsons Sep 28 '15 at 22:41
  • Not works. With this code setTimeout(function () { ; //my pop code }, 5000); I see only the text in my page, popcode disappared. – GDaquila Sep 28 '15 at 22:45
  • of course. You have a random semicolon and the callback contains nothing but a comment. To create a popup use `alert()` – James Parsons Sep 28 '15 at 22:47
  • I starting my popup with a AlertBox. When I click on the button the pop start perfect. I unknow how apply a simply delay on code of popup. Because I use 2 popups, If I not apply a delay, them starting together and 1 is blocked by Chrome. So, I need of a delay on 1 pop code. – GDaquila Sep 28 '15 at 22:50