0

I have a javascript popup window on several pages of my website. I used the a centered popup window I found on Center a popup window on screen?

function popupwindow(url, title, w, h) {
    var left = (screen.width/2)-(w/2);
    var top = (screen.height/2)-(h/2);
    return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

This popup window works on some pages, but not on other pages...

I made 2 pages to show, on the first page the popup works
http://www.weddingpages.nl/test1.php
and on the second page the popup doesn't work:
http://www.weddingpages.nl/test2.php

The source of the pages is exactly the same (copy, paste), only on the second page I deleted the form.

So if I understand correctly, this popup JavaScript only works when there is also a form on the page?

Here is the code of the page where the popup works:

<!DOCTYPE html>
<html>
    <head>
        <title>test1</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

        <script type="text/javascript">
            function popupwindow(url, title, w, h) {
                var left = (screen.width/2)-(w/2);
                var top = (screen.height/2)-(h/2);
                return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
            }
        </script>
    </head>
    <body>
        <form class="form-horizontal" action="" method="post">
            <div class="control-group">
                <label class="control-label" for="title">Naam website / bedrijf:</label>
                <div class="controls">
                    <input type="text" class="span3" id="title" name="title" placeholder="Naam website / bedrijf">
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <button type="submit" name="submit" class="btn">Gegevens opslaan</button>
                </div>
            </div>
        </form> 
        <a href="javascript:popupwindow('http://www.google.com/', title, 1400, 700)">centered Pop up window</a> 
    </body>
</html>

So if you delete the form, the javascript stops working.

Is there anybody who can tell me why ? I am trying to find the solution already for almost 2 days :-(

Community
  • 1
  • 1
Dimitri Visser
  • 155
  • 2
  • 12

2 Answers2

3

You don't have defined "title" params befor pass it to function. try to change this:

<a href="javascript:popupwindow('http://www.google.com/', title, 1400, 700)">centered Pop up window</a> 

with this

<a href="javascript:popupwindow('http://www.google.com/', 'real title', 1400, 700)">centered Pop up window</a> 
joeyramone76
  • 241
  • 1
  • 4
1

Looks like you need to change title to something else because title is an element in your form.

<a href="javascript:popupwindow('http://www.google.com/', title, 1400, 700)">centered Pop up 
window</a> 
Aaron Kurtzhals
  • 2,036
  • 3
  • 17
  • 21