SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    United States
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Javascript Pop-Up Code

    Right now, I'm using code where I have to use <script> tags every time I want to use a pop-up that is a different size than another pop-up link on that page.

    Here's the code:

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=330,height=340,left = 312,top = 234');");
    }
    </script>
    As you can see, I need to specify all the attributes in the script itself.

    Is there any way I can have one universal <script> piece of code in the <head> tag, then specify all the attributes when I create the link on the page?

  2. #2
    SitePoint Guru siphilp's Avatar
    Join Date
    Nov 2001
    Location
    Fife, Scotland
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,
    Is this for a static page or is the script going to be used within a server generated page e.g. PHP, ASP, ASPX?


    Regards


    Simon

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    United States
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is going to be used inside a PHP page.

  4. #4
    SitePoint Guru siphilp's Avatar
    Join Date
    Nov 2001
    Location
    Fife, Scotland
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i might be going about this the long way.

    How many different window sizes do you want to use?

    the reason i have asked before is that it is possible to use one <script> for the open window function you require.

    plus i may be able to give you a complete solution.


    plz note have been infront of Visual Studio and SQL server all day so might not reply till tomorrow hope this is ok.


    regards

    Si

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    United States
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure how many different window sizes I'll be using; I come across that as I make the pages. Which is why I'd like just one universal script tag up in the header, then as I make the pages, I can simply add the attributes to the <a href> tag itself.

  6. #6
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I hope this is what you need:

    Just put the popUp function in the head section but pass to the function the url's page you want to display and the window properties too.

    Here is the code:
    Replace the urls's with your pages:

    <html>
    <head>
    <title>popUp Windows</title>
    <script language="javascript">
    function popUp(URL,properties){
    day = new Date();
    id = day.getTime();
    eval("page"+id)=window.open(URL, 'innerName',properties);
    }
    </script>
    </head>
    <body>
    <br>
    <div align="center">
    <a href="javascript:popUp('page1.php','toolbar=0,scrollbars=0,resizable=1,location=0,width=330,height=340,left=200,top=10')">popUp1</a>
    <br>
    <br>
    <a href="javascript:popUp('page2.php','toolbar=1,scrollbars=0,location=1,width=250,height=350,left=100,top=10')">popUp2</a>
    </div>
    </body>
    </html>

    Best Regards

    Alex

  7. #7
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    United States
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks mixale, that's just what I was looking for.

  8. #8
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm glad that helped.
    You are very welcome Justin Hancock.

    Kindest Regards

    Alex


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
  •