help with javascript - centering a modal dialog

Posted on 2014-01-16
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

Question by:HLRosenberger
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

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 = "";
        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


Author Closing Comment

ID: 39789456

Expert Comment

ID: 39789527
Thank you!

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

728 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