Afternoon everyone – Onclick of “contact “Pop-Up “Contact-Sms-Centre.php'

Can anyone help with this – iv got a php page that returns the following as part of a set of results

<a href='Contact-Sms-Centre.php'>Contact</a> $city $country<hr

The contact sms centre is width=450,height=350'

I also have the popup.php as shown below

<html>

<head>
</head>
<body>
<?php
print "<script type='text/javascript'>";
print "window.open('Contact-Sms-Centre.php','new_window1','status=1,scrollbars=0,resizable=0,menu=no,left=450,top=275,width=450,height=350');";
print "</script>";  
?>
</body>
</html>

The Only way I can get the POPUP to work is if I open popup.php and press refresh ???
This action will POPUP the contact-sms-centre but it also leaves the blank popup.php in the back ground.

How I’d like it to work is –

Once I click on “Contact” in the following code <a href='Contact-Sms-Centre.php'>Contact</a> $city $country<hr I would like the sms-centre window to popup on the page the above results are returned too ?? for this example the results page is named results.php

If anyone can reply with how to achieve my goal with the popup and explain where I am going wrong

Help, like always is very much appreciated – as is – Your input.

Dani AI

Generated

A reliable, future‑proof fix is to open the contact window directly from the results page’s click event instead of navigating to a tiny server page that prints JavaScript. That explains the “blank popup.php” behaviour: loading popup.php leaves the browser on that page (it only prints script), which is why the separate refresh seemed to trigger the popup. was on the right track—call window.open from the click handler and prevent the normal navigation so the current page stays visible.

Unobtrusive (preferred) pattern — keep the href for non‑JS fallback, attach a handler that opens the popup and prevents default navigation:

<a class="contact-popup" href="Contact-Sms-Centre.php">Contact</a>
document.addEventListener('click', function (e) {
  var a = e.target.closest && e.target.closest('a.contact-popup');
  if (!a) return;
  e.preventDefault();
  var w = 450, h = 350;
  var left = Math.round((screen.availWidth - w) / 2);
  var top  = Math.round((screen.availHeight - h) / 3);
  var features = 'width=' + w + ',height=' + h + ',left=' + left + ',top=' + top + ',resizable=0,scrollbars=0';
  window.open(a.href, 'ContactSmsCentreWindow', features);
});

If popup blockers are a concern, use an in‑page modal (overlay) that loads the PHP into an iframe. This avoids separate windows and gives a nicer UX:

<a class="contact-modal" href="Contact-Sms-Centre.php">Contact</a>

<div id="sms-modal" style="display:none;position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);width:460px;height:360px;background:#fff;">
  <button id="sms-close">Close</button>
  <iframe id="sms-frame" src="" width="100%" height="100%"></iframe>
</div>

Load the href into #sms-frame on click and hide/show the modal with style.display or classList.

Quick troubleshooting notes: 1) window.open must run synchronously as a direct response to the click (no setTimeout/AJAX in between) or some browsers will block it. 2) Reuse a fixed window name (second arg to window.open) to avoid multiple windows. 3) In ’s sample there’s a mismatched closing tag (</button> used after <a>), which will break the DOM and make hide/show handlers fail — fix markup and use display or classList.toggle rather than legacy document.layers code.

Recommended Answers

All 4 Replies

Hi there,
What you could try is changing your link from instead of having an href attribute, make an onclick attribute and put that line of javascript from your popup.php file into the onclick's value without the script tags etc. Example: <a onclick='window.open('Contact-Sms-Centre.php','new_window1','status=1,scrollbars=0,resizable=0,menu=no,left=450,top=2 ....) '>Contact</a>

I'm not sure if this will work for you because I'm not 100% sure what you're trying to achieve, but good luck. Let me know if it works :)

Hi there,
What you could try is changing your link from instead of having an href attribute, make an onclick attribute and put that line of javascript from your popup.php file into the onclick's value without the script tags etc. Example: <a onclick='window.open('Contact-Sms-Centre.php','new_window1','status=1,scrollbars=0,resizable=0,menu=no,left=450,top=2 ....) '>Contact</a>

I'm not sure if this will work for you because I'm not 100% sure what you're trying to achieve, but good luck. Let me know if it works :)

Hi.... thanks for your reply -

Im trying to open contact-sms-centre as a POPUP window - from the results page.

Im not sure how to create an "onclick event"

a popup, will get blocked on more browsers every day,
and get flagged as malicious,
whether it is or not
this code scrap creates a link that opens or closes a layer above the current page at the link location, put your contact details in it, and <?php include('poplayer.inc.php'); ?> or paste the code
wherever you want the link to appeartables are passe, its example code prettify it up with your css

<!--poplayer.inc.php-->
<script language="javascript" type="text/javascript">
<!--
(document.getElementById) ? dom = true : dom = false; //check ie or ff
function hideIt(layer) {
 if (dom) {document.getElementById(layer).style.visibility='hidden';} //ie
 if (document.layers) {document.layers[layer].visibility='hide';} } //ff
function showIt(layer) {
 if (dom) {document.getElementById(layer).style.visibility='visible';}
 if (document.layers) {document.layers[layer].visibility='show';} }
//-->
</script>
<a href='#' onClick="showIt('layer1');">Contact Us</button>
<div id="layer1" style="visibility:hidden;">
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td align="right" onClick="hideIt('layer1')">Close</td>
</tr>
<tr>
<td>
<UL compact>
<li>in this case the content of the popup page goes in this div</li>
<li>bla bla bla bla</li>
<li>bla bla bla bla</li>
<li>bla bla bla bla</li>
<li>bla bla bla bla</li>
<li>bla bla bla bla</li>
<li>bla bla bla bla</li>
</ul>
</td>
</tr>
<tr>
<td align="right" onClick="hideIt('layer1')">Close</font>
</td>
</tr>
</table>
</div>

Hi, many thanks for your reply many weeks ago,

I have started looking into this and whilst the js script opens the "layer" clicking close does not close the layer.

can anyone help with this please...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.