Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:02

Positioning a URL to open to center of page...


Poster: rudy
Dated: Sunday May 27 2012 - 1:25:46 BST

I have been using this code to link to this web page, but I would really like is to be able to set the "top" position as it is (35) but I would like the page to open in the center of the page. This way, it would always be in the center regardless the the persons screen/monitor size. Sure would appreciate some help coding this.

aI("text=Exam Objectives;oncolor=#FFFFFF;offcolor=#000000;url=http://www.networkdriven.com/aplus-questions/aplus_focus_2009.htm;target=blank;targetfeatures=width=768,height=510,top=35,scrollbars=yes,left=285 toolbar=no,location=no,status=yes; status=Exam Objectives;");

Thanks

Re: Positioning a URL to open to center of page...


Poster: Ruth
Dated: Sunday May 27 2012 - 16:50:04 BST

Hi Rudy :)

OK, I have what you need. I'll post the whole function and then give you how to do it for the menu_data.js file. You'll probably want to put the original someplace as it has explanations as to setting width and height, and the attributes part which you would only use what you wanted. I guess you can set status at yes, but as far as I know the only thing that shows as to status would be the url. In this case it would show something like javascript centeredWin [ url of your page]. Browsers no longer show what you write, since that was a security vulnerability and phising became so prevalent it was removed. OK, below the script is the info on how to do it in the data file.
Code:
<script language="JavaScript" type="text/javascript">
<!-- Copyright 2001, Sandeep Gangadharan -->
<!-- For more free scripts go to http://sivamdesign.com/scripts/ -->
<!--
x = parseInt(window.screen.width) / 2 - 175;  // the number 175 is the exact half of the width of the pop-up so should be changed according to the size of the pop-up you want
y = parseInt(window.screen.height) / 2 - 67;  // the number 67 is the exact half of the height of the pop-up and so should be changed according to the size of the pop-up you want

function centeredWin() {
CW=window.open('window.html','NewWin','toolbar=no,menubar=no,location=no,resizable=no,status=no,width=350,height=135,scrollbars=no')
        // change the figures of width and height above to customize the size of the window to be opened.
CW.moveTo(x,y);
}
// -->
</script>


Now as to using it. As you see this is a copyrighted script but it is free to use as long as copyright info is present in the data file and the head of your documents where it is use i.e. where the menu is.

Code:
<!-- Copyright 2001, Sandeep Gangadharan -->
<!-- For more free scripts go to http://sivamdesign.com/scripts/ -->


Then in the menu data file you would put this right after the top section that has the global settings for opening and closing delays and subOffsets. You'll see that I changed the numbers for width and height as noted in the original function to 1/2 of what you had set for the width and height as required.

Code:
// Copyright 2001, Sandeep Gangadharan
// For more free scripts go to http://sivamdesign.com/scripts/ -->

c = parseInt(window.screen.width) / 2 - 384;   //This is 1/2 the size you had in your original, opens the window at  width 768
d = parseInt(window.screen.height) / 2 - 255;  //this is 1/2 the size you had in original, opens window at height 510

function centeredWin() {
CW=window.open('aplus_focus_2009.htm','NewWin','toolbar=no,menubar=no,location=no,resizable=no,status=yes,width=768,height=510,scrollbars=yes')
CW.moveTo(c,d);
}


Now, the aI string is this

Code:
aI("text=Exam Objectives;url=javascript:centeredWin('aplus_focus_2009.htm');");

Note that I substituted your height, width settings and then in the function CenteredWin, I used your page url. I checked it in Netscape 9, Opera 9, 10, Safari 5.1.5, Google Chrome [very old one] Firefox 3.0.1.9, and 3.6.8 and 11, and IE8 and it works in all.

For your information, this was the only script I could find which did this and has the attributes in the script and not in the 'link' All the rest had a script but you had to put the height, width, status, toolbars etc in the url link, which with the data file I couldn't do. I did try others, and they worked until I put the targetfeatures in the aI string, at that point it was as if the function no longer was working since it opened always at left and top 0

Hope this helps :) Sorry this post is so long, I never know what to leave out in explanation since I don't know the level of knowledge people have as to functions [mine is pretty limited]

Ruth

Re: Positioning a URL to open to center of page...


Poster: rudy
Dated: Monday May 28 2012 - 0:19:45 BST

Hi Ruth - WOW, that was a ton of work you did!!! Thanks so very much!!

Does the JavaScript code go into the page that will ultimately be opened by the code in this code aI("text=Exam Objectives;url=javascript:centeredWin('aplus_focus_2009.htm');"); If so, probably in the <head></head> part of the HTML page?

Thanks again, I can't believe you did all this :D

Re: Positioning a URL to open to center of page...


Poster: Ruth
Dated: Monday May 28 2012 - 4:32:25 BST

You're welcome. I enjoy searching and learning new things, and I really like Milonic menus and playing around with them.

No, the code goes in the menu_data.js file just below the global settings. Your data file would look like this at the top

Code:
fixMozillaZIndex=true; //Fixes Z-Index problem  with Mozilla browsers but causes odd scrolling problem, toggle to see if it helps
_menuCloseDelay=500;
_menuOpenDelay=150;
_subOffsetTop=2;
_subOffsetLeft=-2;

// Copyright 2001, Sandeep Gangadharan
// For more free scripts go to http://sivamdesign.com/scripts/ -->

c = parseInt(window.screen.width) / 2 - 384;  // the number is the exact half of the width of the pop-up size you you set
d = parseInt(window.screen.height) / 2 - 255;  //the number is the exact half of the height of the pop-up size you want

function centeredWin() {
CW=window.open('aplus_focus_2009.htm','NewWin','toolbar=no,menubar=no,location=no,resizable=no,status=yes,width=768,height=510,scrollbars=yes')
CW.moveTo(c,d);
}


Then the aI string is as you posted:
Code:
aI("text=Exam Objectives;url=javascript:centeredWin('aplus_focus_2009.htm');");


However, since this is a copyrighted script you do need to put that info in the head on every page where you have the menu with this link. I guess you could put it in the page that is opening, too, but that doesn't have a menu so I'd forget it. I don't know how many pages you have or if you use an editor in which you are piecing together things like head/body etc. like some of them do, or a template. If you do, it's pretty easy to insert that copyright. You'd just put this in the head area
Code:
<!-- Copyright 2001, Sandeep Gangadharan -->
<!-- Function centeredWin at http://www.sivamdesign.com/scripts/popups.html-->
<!-- For more free scripts go to http://sivamdesign.com/scripts/ -->

If you don't have an editor like that, or a template, I guess you'd have to do it on each page. That's because you are not using the function on the page that opens, but on every page where the Milonic menu has that particular link.

Hope that helps.

Ruth