Centering a DIV Window with Cross-Browser JavaScript

by demtron on Wednesday, January 14, 2009 02:28 PM

Years ago, I wrote a little bit of JavaScript to position a DIV control in the center of a browser window space by calculating the browser area, the window size, then determine the coordinates of the place where the DIV would need to be placed.  Since I forgot where I put it and it brobably wouldn't be cross-browser compatible anyway (orginally written for IE 5/6), I searched the web and ran across this JavaScript centering code that accomplishes exactly that.  Here are the excerpts of the code needed to do this.

window.size = function()
var w = 0;
var h = 0;
//strict mode
if(!(document.documentElement.clientWidth == 0))
w = document.documentElement.clientWidth;
h = document.documentElement.clientHeight;
//quirks mode
w = document.body.clientWidth;
h = document.body.clientHeight;
w = window.innerWidth;
h = window.innerHeight;
return {width:w,height:h};
} = function()
var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
var _x = 0;
var _y = 0;
var offsetX = 0;
var offsetY = 0;
//strict mode
if(!(document.documentElement.scrollTop == 0))
offsetY = document.documentElement.scrollTop;
offsetX = document.documentElement.scrollLeft;
//quirks mode
offsetY = document.body.scrollTop;
offsetX = document.body.scrollLeft;
offsetX = window.pageXOffset;
offsetY = window.pageYOffset;
_x = ((this.size().width-hWnd.width)/2)+offsetX;
_y = ((this.size().height-hWnd.height)/2)+offsetY;

Here's some example code to show how it's supposed to be used:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<script type="text/javascript" src="Window.Size.js"></script>
<script type="text/javascript">
function showCenter(point)
var div = document.createElement("div"); = "#dedede"; = "absolute"; = point.y + "px"; = point.x + "px"; = "100px"; = "100px";
<div style="height:1200px"></div>
<input type="button" value="Get Center" onclick="showCenter({width:100,height:100}))"/>


Blog Auto-Subscribe and Auto-Discovery Setup

by demtron on Friday, January 09, 2009 11:11 AM

Aggregator tools are great for following your favorite blogs and managing what content might be most important for you to explore further.  If a visitor knows how to find an RSS blog feed, then it's easy for him to add his blog to his aggregator.  However, many visitors are not tech savvy and may not be able to figure out how to find a feed.  Will they be disappointed and not return to your blog again?

It's easy to add auto-discovery code your blog pages to facilitate feed subscription. To accomplish this, just add this code within the <head>section of your site HTML code:

<link rel=”alternate” type=”application/rss+xml” title=”Your Title” href=”” />

With this code, any auto-discovery tool can find this code and allow for easy addition of the blog feed. If your blog offers multiple feeds for different formats or different categories, this code can be repeated for each feed.

Good luck and happy blogging!


Satyam Accounting Scandal - My Take

by demtron on Thursday, January 08, 2009 11:22 AM
I found this article titled Accounting Scandal Rocks Indian Outsourcer Satyam over at InformationWeek.  It’s likely that a number of companies do not have contingency plans for this kind of problem.   According to this article, some of the work done by Satyam may not be easily transferable to other IT consulting companies. What does this mean for the state of IT offshoring to foreign companies?

First, there will likely be greater scrutiny of outsourcing firms and increased financial disclosure requirements.  Do outsourcing clients understand how to analyze the financials of foreign companies and find indications of fraud or other problems that can happen in that country but not domestically?  Would increased scrutiny have identified this?  I can’t answer these questions, but I’ll bet they’ll be raised really quickly.

Second, the article mentions the lack of vendor diversity for specific lines of IT work.  A one-vendor strategy for each line makes a lot of sense for economics, communication, project management and whole range of other reasons.  With the Satyam scenario, the disruption of service appears to be very likely for most clients.  What would happen to your business if, for example, you Internet marketing consultants were suddenly unavailable to continue working with you?  How difficult would it be to find a replacement to pick up the pieces and how much would that cost?

Third, while it might be unfair, I feel this will cast a long shadow on the outsourcing and offshoring industry.  I disagree with the statement that this will not cause U.S. customers to shun outsourcing.  The fraud that exists in this case is of a magnitude that should give pause to creating future offshoring relationships.  Fraud at this level likely means that fraud exists at lower levels in the organization.  The inflation of financial figures likely affected the negotiations of contracts and swayed the confidence of prospective clients.  If I were a client, I would run (not walk) away as quickly as possible and probably bring my IT operations back to the U.S., if not long term, I would at least until I could make a thorough assessment of what this means for potential relationships with other offshoring vendors.

This problem will not go away.  With the kind of gaudy numbers that have circulated about the volume and values of offshoring contracts in recent years, it’s hard to imagine that Satyam is the only problem.

Identifying a Nullable Type Programmatically in Visual Studio

by demtron on Tuesday, December 16, 2008 05:34 PM

I have occasionally found a need to identify whether the type of a given variable is a nullable type so that I know whether I need to also use the HasValue and Value methods to obtain its contained value.  Here's a farily simple snippet of code to accomplish this.

If type.IsGenericType AndAlso type.GetGenericTypeDefinition() = GetType(Nullable(Of )) Then
End If
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) {}

Powered by BlogEngine.NET
Theme by Mads Kristensen · Adapted by Demtron

Bookmark and Share


<<  March 2017  >>

View posts in large calendar
Log in

Milwaukee SEO Company

Milwaukee Access Programmer/Developer

Milwaukee Website Designer and Developer

Marketing / SEO

Blog Directory
blogarama - the blog directory
Milwaukee area SEO, SEM, ASP.Net