#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    How to merge, combine two different functions in javascript?


    Hello, world! I need help on something.I don't know much about javascript and I have two different scripts to merge, combine or whatever you wanna call it:

    function doSomething() {}

    (function loop() {
    var rand = Math.round(Math.random() * (30000 - 1000)) + 1000;
    setTimeout(function() {
    alert('A');
    doSomething();
    loop();
    }, rand);
    }());

    And this one:

    var win=null;
    function NewWindow(mypage,myname,w,h,scroll,pos){
    if(pos=="random"){LeftPosition=(screen…
    if(pos=="center"){LeftPosition=(screen…
    else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20…
    settings='width='+w+',height='+h+',top…
    win=window.open(mypage,myname,settings…

    Can someone help me on this matter?

    Many thanks to everyone.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    And how exactly are these two supposed to be merged? Create popup windows randomly every 1-30 seconds? I sure hope not because that sounds very, very annoying.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by requinix
    And how exactly are these two supposed to be merged? Create popup windows randomly every 1-30 seconds? I sure hope not because that sounds very, very annoying.
    The script above is just an example. I have found it in the internet.I'll change the time when the main problem is solved: how to merge the scripts.

    Thankyou for the reply.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Originally Posted by tekton
    I'll change the time when the main problem is solved: how to merge the scripts.
    Again: Merge how? What is the resulting script supposed to do?

    We won't be able to help you until you've specified this.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by Jacques1
    Again: Merge how? What is the resulting script supposed to do?

    We won't be able to help you until you've specified this.
    Sorry about that.You might have noticed that I'm from another country.My english is not that good.What I want is a popup that appears randomly at a certain time(not 30 seconds,of course) and at a certain point of the screen, when the page is loaded.This is for a game for my website.When the popup appears, the user will click on it and be redirected to another page.

    A guy from another forum gave me this:

    function doSomething(){}

    function NewWindow(mypage,myname,w,h,scroll,pos){
    if(pos=="random"){
    LeftPosition=screen…
    }
    if(pos=="center"){
    LeftPosition=screen…
    }
    else if((pos!="center" && pos!="random") || pos==null){
    LeftPosition=0;
    TopPosition=20…
    settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',l ocation=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    win=window.open(mypage,myname,settings);
    }

    function loop() {
    var rand = Math.round(Math.random() * (5000 - 1000)) + 1000;
    setTimeout(function() {
    alert('A');
    doSomething();
    loop();
    }, rand);
    }

    var win=null;
    NewWindow();
    loop();

    But, there's a syntax error on line 11 an i can't fix it.

IMN logo majestic logo threadwatch logo seochat tools logo