SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    WebAmoeba mythix's Avatar
    Join Date
    Aug 2002
    Location
    here
    Posts
    578
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Call java function in body tag?

    hi,

    First thing, my java is non existant.

    I want to take a popup function and cause it to open Xseconds after the parent page has opened.

    This is the script i want to run:

    PHP Code:
    <script type='text/javascript'>
    <!--
    function 
    MM_openBrWindow(theURL

        
    newWin open(theURL);
    }
    //-->
    </script> 
    I altered it a little, just want to check i cut down newWin = open(theURL ,winName, features); not to include features and winName, I assume that these are NOT required attributes?

    How do i do this?

    Thanks
    Laws are like sausages. You have much more respect for them if you haven't actually seen how they're made.

    http://www.webamoeba.co.uk

  2. #2
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firstly, java isn't the same thing as javascript.
    (See here to read about the difference.)

    --

    Code:
    <script type="text/javascript">
    
    function delayedPop() {
    setTimeout("window.open('destination.html')",4000);
    }
    
    </script>
    
    ...
    
    <body onload="delayedPop()">
    ...
    setTimeout delays are set using milliseconds.
    4 seconds = 4000 milliseconds.

    I tried keeping the url as a variable that could be set in the event (onload) but it was not recognising the value being set for the url.

    If the destination url and the length of delay are constant then you can use the above code where both values are hard-coded into the script.

    Fwiw, keeping the delay as a variable (that could be set in the event onload) seemed to work without problems.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  3. #3
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you could do it this way
    <html>
    <head>
    <title>Open Window</title>
    <SCRIPT LANGUAGE="JavaScript">
    function OpenWin(theurl,winname)
    {
    NewWin=window.open(theurl,winname)
    }
    </SCRIPT>
    </head>
    <body onLoad=setTimeout('OpenWin("page1.html","win1")',2000)>
    </body>
    </html>

    This would open the window after 2000 miliseconds (2seconds)

  4. #4
    WebAmoeba mythix's Avatar
    Join Date
    Aug 2002
    Location
    here
    Posts
    578
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks i will go and try them now!
    Laws are like sausages. You have much more respect for them if you haven't actually seen how they're made.

    http://www.webamoeba.co.uk

  5. #5
    WebAmoeba mythix's Avatar
    Join Date
    Aug 2002
    Location
    here
    Posts
    578
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe i wasn't vlear, I only wanted the popup to appear once. But it keeps on creating new windows every Xmilliseconds . How do i stop this?
    Laws are like sausages. You have much more respect for them if you haven't actually seen how they're made.

    http://www.webamoeba.co.uk

  6. #6
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Try this one out. It should be noted though, that pop-up blockers (like the one built into Mozilla) will take this out, so please have another mode of navigation handy if this is essential to your site.
    Code:
    <head>
    <script type="text/javascript">
    var newWin;
    function delayedWindow () {
     setTimeout("newWin = window.open('somepage.html', 'newWin');", 2000);
    }
    </script>
    </head>
    <body onload="if (!newWin) {delayedWindow();}">

  7. #7
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unless you are reloading the Parent window my example should only open the popup once.


Bookmarks

Posting Permissions

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