Forum Moderators: open

Message Too Old, No Replies

javascript to open fixed height popup

         

kapow

12:56 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can anyone tell me how to make a window open with a reduced height (width doesn't matter).

It is an enquiry form, because the form is quite wide I want the window to be say 200 px high so the visitor can see it is a new window - and continue browsing the site whilst adding items to the enquiry form.

Not being very good with Javascript I cobbled this together, but it doesn't work:

<a href="javascript:window.open('enquiry.php','','height=200,left=80,top=80')">ENQUIRIES</a>

BlobFisk

12:59 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



window.open('address.html,'Popup Title','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=800,height=400,top=80,left=80');

HTH

kapow

1:52 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks BobFisk. I took your code and made this:

<a href="javascript:window.open('enquiry.php','Popup Title','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=800,height=400,top=80,left=80');">ENQUIRY FORM</a>

It doesn't work the way I've done it.

ytswy

2:03 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



Are you meant to put the javascript in the href? I've always used onClick=window.open('...etc and just set href="#"

BlobFisk

2:05 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bizarre,

Try it as a script. In your <head>:


<script type="text/javascript">
function openPopup(theURL)
{
window.open(theURL,'Title','toolbar=no,location=no,
directories=no,status=no,menubar=no,scrollbars=no,
resizable=no,width=800,height=400,top=80, left=80');
}
</script>

Then, in your <body>:


<a href="javascript:openPopup('address.php')" ...>

Do you have JavaScript debugging on? If so, what does it say?

BlobFisk

2:07 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey ytswy,

You can put JavaScript in the href, as long as you preface your code with javascript:. This does not apply to onClick etc. as these are event handlers and expect a script of some sort.

However, putting scripts in the href is not best practice, and they are best left in the event handlers.

ytswy

2:09 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



Cheers BlobFisk, live and learn :)

kapow

2:56 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



THANKYOU

It works now :)
I did it this way:

<head>
...
<script type="text/javascript">
function openPopup(theURL) { window.open(theURL,'Title','toolbar=no,location=no, directories=no,status=no,menubar=no,scrollbars=yes, resizable=no,width=820,height=400,top=80, left=80'); } </script>
</head>

<a href="javascript:openPopup('enquiry.php')">ENQUIRIES</a>

I would have preferred a method without putting stuff in the head tag as it is more to manage when I update things. But it works, so I am happy - thanks