dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: running javascript function once

  1. #1
    Join Date
    Mar 2012
    Posts
    2

    running javascript function once

    I want to open new window onMouseOver
    but I want the window to open only once.
    how can i do that?
    here is my code:

    <html dir="rtl">
    <head>
    <script langugae="javascript">
    function openWin(){
    window.open('http://google','bigOne','width=900,height=600')
    }
    </script>
    </head>
    <body>
    <a href="http://tvengine.host56.com/new/index.php"
    onMouseOver="openWin('')">
    click here
    <a>
    </body>
    </html>

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    Simplest way:
    Code:
    var openp = true;
    function openWin(){
      if (openp) {
        window.open('http://google','bigOne','width=900,height=600');
        openp = false;
      }
    }

  3. #3
    Join Date
    May 2017
    Posts
    2
    Quote Originally Posted by Declan1991 View Post
    Simplest way:
    Code:
    var openp = true;
    function openWin(){
      if (openp) {
        window.open('http://google','bigOne','width=900,height=600');
        openp = false;
      }
    }

    This does not work once you reload the page.this should be validated to work even on reloading page. How to do that??

  4. #4
    Join Date
    May 2017
    Posts
    2
    This does not work once we reload the page. so how to make this function even on reloading page.

  5. #5
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,709
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
    <title></title>
    </head>

    <body>
    <a href="http://tvengine.host56.com/new/index.php"
    onMouseOver="openWin(10);">
    where parameter 0 = the number of days persistence
    <a>

    <script type="text/javascript">

    function openWin(days){
    var re=new RegExp('openWin'+'=[^;]+','i');
    var c= document.cookie.match(re)?document.cookie.match(re)[0].split("=")[1]:null;
    if (!c) {
    window.open('http://google','bigOne','width=900,height=600');
    days!=-1?document.cookie='openWin=true'+(typeof(days)=='number'?';expires='+(new Date(new Date().getTime()+days*86400000).toGMTString())+';path/;':';'):null;
    }
    }



    </script>
    </body>

    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  6. #6
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,709
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
    <title></title>
    </head>

    <body>
    <a href="http://tvengine.host56.com/new/index.php"
    onMouseOver="openWin(10);">
    where parameter 0 = the number of days persistence
    <a>

    <script type="text/javascript">

    function openWin(days){
    var re=new RegExp('openWin'+'=[^;]+','i');
    var c= document.cookie.match(re)?document.cookie.match(re)[0].split("=")[1]:null;
    if (!c) {
    window.open('http://google','bigOne','width=900,height=600');
    days!=-1?document.cookie='openWin=true'+(typeof(days)=='number'?';expires='+(new Date(new Date().getTime()+days*86400000).toGMTString())+';path/;':';'):null;
    }
    }



    </script>
    </body>%0
    Last edited by vwphillips; 05-10-2017 at 10:26 AM.
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center