Solved

help with javascript - centering a modal dialog

Posted on 2014-01-16
3
231 Views
Last Modified: 2014-01-17
I have this code that I use to center a modal dialog.    it used to work for IE and Firefox.  My harddrive crashed, and I had to reinstall my entire development environment.    Now, this code works for IE,  but not Firefox.  Any idea why?   Any better way to center a modal dialog?

       
var WIDTH = 850;
	var HEIGHT = 850;
		
	function ShowIncident(incident_id) {
 	
		var top = (screen.height / 2) - (HEIGHT / 2) ;
    	       var left = (screen.width / 2) - (WIDTH / 2);
								
		page = "../tds_incident/ShowTds_Incident.aspx?Tds_incident=" + incident_id
		mywindow = window.showModalDialog(page, null,
			"scroll:yes; resizable:no; help:no; " +
			"dialogTop:" + top + "px;" +
			"dialogLeft:" + left + "px; " +
			"dialogWidth:" + WIDTH + "px; " +
			"dialogHeight:" + HEIGHT + "px; ");
			
	}

Open in new window

0
Comment
Question by:HLRosenberger
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
dimmergeek earned 500 total points
ID: 39786896
Using '=' instead of ':' seems to help.

You can also add centerWindowOnScreen() after the window opens

var WIDTH = 850;
        var HEIGHT = 850;

        var top = (screen.height / 2) - (HEIGHT / 2);
        var left = (screen.width / 2) - (WIDTH / 2);

        var page = "http://www.experts-exchange.com";
        mywindow = window.showModalDialog(page, null, "scroll=yes, resizable=no, help=no, dialogTop=" + top + "px, dialogLeft=" + left + "px, dialogWidth=" + WIDTH + "px, dialogHeight=" + HEIGHT + "px");
        mywindow.centerWindowOnScreen();

Open in new window

0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 39789456
thanks.
0
 
LVL 7

Expert Comment

by:dimmergeek
ID: 39789527
Thank you!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now