• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 912
  • Last Modified:

PHP and popup box

Hello,

Is there a way to resize a window with PHP that was opened using PHP. I need a small popup window that does not get blocked by popup blockers.

Bob
0
weikelbob
Asked:
weikelbob
  • 7
  • 2
2 Solutions
 
RoonaanCommented:
Good popup blockers allow popups to show when they are part of event handling users initiated (click/dblclick usual).

Also, you have to recognize that PHP can NOT open a window because it is a SERVERside language. You can however use PHP to generate Javascript which triggers the opening of a new window.

A window created by Javascript could be resized by PHP outputting additional sizing javascript codes, but it would be more senseful to have Javascript open the window in the correct size from starters:

<script type="text/javascript">
function newWindow(locationUrl, height, width)
{
     window.open(locationUrl, 'popup', 'height=' + height + ',width=' + width);
}
</script>

<a href="popup.php" onclick="newWindow('popup.php',200,200);return false;">Click</a>

-r-
0
 
jdpipeCommented:
When you say 'resize a window that was opened using PHP' I assume you mean that you have TWO different PHP pages and you want to resize a popup (previously opened in your first page) from your second page.

My investigation seems to suggest that you can do this fine in Mozilla but that Internet Explorer doesn't let you do this. Have'nt worked you what I'm doing wrong yet -- according to
http://www.windowsitlibrary.com/Content/1160/22/1.html

there should be no problem.

First script:
----------------------------
<html><head><title>test</title>
<script>
function a(s){
      w = window.open('about:blank','aaa','width=200,height=200');
      if(w){
            w.resizeTo(200,200);
            w.document.write(s);
            w.focus();
      }
}

function getw(){
      w = window.open('about:blank','aaa','width=50,height=50');
}
</script>
</head>
<body onload="getw()">
<?php

print("page 1");
print("<br><a href=\"javascript:a('APPLE')\">APPLE</a>");
print("<br><a href=\"test2.php\">test 2</a>");
?>
</body>
</html>
--------------------------------

Second script:
--------------------------------
<html><head><title>test</title>
<script>
function a(s){
      var w = window.open('about:blank','aaa','width=600,height=600');
      if(w){
            w.resizeTo(600,600);
            w.document.write(s);
            w.focus();
      }
}

function getw(){
      w = window.open('about:blank','aaa');
}

</script>
</head>
<body onload="getw()">
<?php

print("page 1");
print("<br><a href=\"javascript:a('ORANGE')\">ORANGE</a>");
print("<br><a href=\"test1.php\">test 1</a>");
?>
</body>
</html>
--------------------------------

0
 
jdpipeCommented:
BTW with the above link, hit 'reload' to see the text.
JP
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
weikelbobAuthor Commented:
I didn't have 2 php sites.

I simply want to have a popup that does not get stopped by popup blockers. -- like Ronaan's example. The thing is, others have said that using the javascrpt 'window.open' command that was started by clicking on a link will be blocked by popup blockers. Which way is it?

Bob
0
 
jdpipeCommented:
I have tested the Mozilla popup block (same in Firefox) and Google toolbar popup blocking feature with the "javascript:a('orange')" links in my example both worked fine.
I think that window.open calls from setInterval and onload events will be blocked, but those resulting for onclick events , especially those from <a> tags, should be fine.

JP
0
 
jdpipeCommented:
In other words, i think that <a href="javascript:makeMyPopup(...)"> will be your best bet. I tested this.
0
 
jdpipeCommented:
sorry.... one last comment

you should always capture the output of the window.open method as follows:

r = window.open(...)

if(!r){
    alert("couldn't open popup window... please check your browser settings and disable your popup blocker if necessary");
}

JP
0
 
RoonaanCommented:
jdpipe,

<a href="javascript:makeMyPopup()"> would not be my preferred way of handeling things; people who have javascript disabled cannot visit your page, because javascript: does not resolve to an url.

Therefor better to use:
<a href="mypopupurl" onclick="makeMyPopup();return false;">

-r-
0
 
jdpipeCommented:
roonaan,

You are right there. The best way is using an onclick event in general.

If you are running a site that you really can't (or can't afford to) design for non-JS users, then perhaps a warning up-front (<noscript>this site depends on the availabilty of Javascript which you don't support, please use another browser or change your browser settings before continuing</noscript>) is better than half-supporting non-JS.

Depends what sort of site this is and what the functionality in question is. Because the question relates to resizing of windows, I assumed that JS-only was the current situation.

Any info on what is/isn't tolerated by any of the other blockers out there?

JP
0
 
jdpipeCommented:
cf. Gmail for example of this 'you need javascript' thing.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now