1
voddie
Centre page popup
  • 2006/8/29 14:07

  • voddie

  • Just popping in

  • Posts: 71

  • Since: 2003/10/20


Hi

I have found the javascript that opens anew popup window and followed a lead in FAQs of how to open a new popup when required.

How do I make the popup be centre of page when opens?

The code in include/xoops.js

*****************
function openWithSelfMain(url,name,width,height,returnwindow) {
var options = "width=" + width + ",height=" + height + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";

var new_window = window.open(url, name, options);
window.self.name = "main";
new_window.focus();
if (returnwindow != null) {
return new_window;
}
}

*****************************
What do I need to change or add?

Thanks in advance

voddie
To ask the hard question is simple

2
zyspec
Re: Centre page popup
  • 2006/8/29 14:42

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


You just need to add the 'left' and 'top' variables to your function and then make sure your calling routine sets them...

Change:
function openWithSelfMain(url,name,width,height,returnwindow) {
var 
options "width=" width ",height=" height ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";


to:
function openWithSelfMain(url,name,width,height,top,left,returnwindow) {
var 
options "width=" width ",height=" height ",top=" top ",left=" left ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";


Set 'top' to where you want the top of the window to be (vertical position) and 'left' to where you want the left edge of the new window to start (horizontal position). The origin is in the upper left-hand corner of the screen.

3
voddie
Re: Centre page popup
  • 2006/8/29 14:47

  • voddie

  • Just popping in

  • Posts: 71

  • Since: 2003/10/20


Hi zyspec

Thanks for the quick response.

Is there anyway that I can make sure that it always opens in the centre no matter what resolution the visitor is using ie 1024x768, 1080x1024?

I.e something that works out the screen resolution and makes the necessary changes?

voddie
To ask the hard question is simple

4
davidl2
Re: Centre page popup
  • 2006/8/29 15:02

  • davidl2

  • XOOPS is my life!

  • Posts: 4843

  • Since: 2003/5/26


Here's a few centering pop-up generators for you

http://www.dynamicdrive.com/dynamicindex8/autocenter.htm

http://javascript.internet.com/generators/popup-window.html

http://simplythebest.net/scripts/DHTML_scripts/javascripts/javascript_65.html

http://www.fg-a.com/java4.shtml

http://www.hotscripts.com/Detailed/34515.html

5
voddie
Re: Centre page popup
  • 2006/8/29 18:54

  • voddie

  • Just popping in

  • Posts: 71

  • Since: 2003/10/20


Hi

Followed the links and this generated code works much better than popups currently using xoops.js.

The problem being that the site name was generated before any code that I entered resulting in a error page

My work around was to add to the xoops.js the following:

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

Then I called it from any location, ie template.html or from any block I created using: put a < before the code!!!! and closing a> after

Quote:
a href="http://www.mysite.com/yournewhtml.html" onclick="NewWindow(this.href,'name','400','400','yes');return false">Yournewhtml</a>


Works a treat and much easier than the orgininal.

Thanks for all who posted help and pointed me in the right direction.

Hope this helps others

Thanks again

Voddie
To ask the hard question is simple

Login

Who's Online

213 user(s) are online (137 user(s) are browsing Support Forums)


Members: 0


Guests: 213


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits