tags:

views:

130

answers:

4

I have this at above the body tag in my page --

<script type="text/javascript">
    $(document).ready(function() {
        $('#button').popupWindow({windowURL:'http://something',centerBrowser:1,width:400,height:300}); 
    });
</script>   

Is there a way to make this popup happen without the user actually clicking a button -- programmatically w/ code inserted into the middle of the page with php on page load?

A: 

I think for security reasons a lot of browsers will not open a popup window without some kind of user action.

John Boker
A: 

popupWindow is hard-coded to work with links, and only responds to "click" events. That said, if you want the popup to appear on page load, you could try editing line 6 of jquery.popupWindow from this;

$(this).click(function(){

to this;

$(this).ready(function(){

add an id to your body element;

<body id="popuptrigger">

and call the plugin;

$('body#popuptrigger').popupWindow({ ... });

This is untested, but even if it works it's not a very elegant solution. I'd suggest looking around for a popup plugin that allows you more flexibility. I use jqModal to load internal url requests for popup forms and can throughly recommend it. Your mileage mey vary though, so do a google search for "jquery modal" and check out some alternatives.

MatW
A: 

I'd suggest using a jQuery UI Dialog. That way you won't have to worry about how different browsers handle popups differently.

Rowno
+1  A: 

Add the following next.

$("#button").trigger("click");

Or put it all on on chained line:

$('#button').popupWindow({...options...}).trigger("click");

For what it's worth, you can invoke this from a non-rendered element:

$("<div></div>").popupWindow({..options..}).click();
Jonathan Sampson