Thursday, July 12, 2012

window.onload problem on external javascript with lower versions of IE

I was happily developing a new application, and have been very happy with the results.  Then as I was in the middle of implementation, (good thing it was still early stages) I realized that IE browsers versions 5-7 acts abnormally on the window.onload from an external javascript.  Although, my application works on all current browsers, this still shows as a dilemma to me because, the websites I am going to use my application on have visitors that will use mostly old versions of IE, based on Google Analytics data.  The only way I can sleep at night knowing my application behaves as it should, is to find a solution for this problem or not implement my application at all.

I keep getting an error of "Invalid Pointer", which could be due to the fact that script somehow ran before all the objects and elements have completely loaded.  After a exhausting search, I was able to find the solution in an easy to understand blog by Dean Edwards at his site: http://dean.edwards.name/weblog/2005/09/busted/ and http://dean.edwards.name/weblog/2006/06/again/ .

The solution on my specific problem was to have my external page loaded after all objects and elements are finish on the main page.  One of the solution presented was to have defer on the <script> tag.  According to him, this only works on external files, which pretty much the solution on my problem.  Here is how it would look:

<script defer type="text/javascript" src="external.js"></script>

Ok, so I placed that on my website.  Still an error occured, I have no choice, but to just have my functions in an external file, while I do the window.onload on the main page.

After placing the window.onload on the main page, this time the error is on the browser not recognizing the object.  So part of the solution is for IE to detect, if everything is ready.  Answer is still in Deans blog, but a lot different for my case since, I want to use an external file and detect if all is ready, before I run the function.  My own solution is to have the following script, based on his example:


document.onreadystatechange = function() {  
if (this.readyState == "complete") { 
somefunction(); 
}};

I just replaced his script object with document object, for me to see that document has all been loaded.  This only works on IE according to some websites, but when I placed it to run on other browser was detected, it still performs as it should.

So, the whole solution for me was to detect in PHP, the browser and version to run this work around:

<script defer type="text/javascript" src="external.js"></script>

<?php 
if(isset($_SERVER['HTTP_USER_AGENT']) && ((strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5') !== false) || (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) || (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false)))
{
?>

document.onreadystatechange = function() { if (this.readyState == "complete") { 
somefunction(); 
}};
<?php
}
else
{
?>
<!-- Other Browsers Script -->
<?php
}
?>


The following is the source for the onreadystatechange: http://help.dottoro.com/ljerfwdm.php

Tuesday, July 3, 2012

Installing MS SQL 2008 Management Studio

I'm making this post, since I have seem to have solved my installation problem with MS SQL 2008 Management Studio installer.  And I want to share, the proven way in solving it.  Somehow, solved anyway.  I don't know what exactly the problem with the installer, but when you try to install it, it gives the following message:


SQL Server Setup failure.
------------------------------
SQL Server Setup has encountered the following error:
Invoke or BeginInvoke cannot be called on a control until the window handle has been created..

I looked for a solution thru google, and this is the most funny and unbelievable work around I found, but it works.  Here is the link: http://stackoverflow.com/questions/1677435/invoke-or-begininvoke-cannot-be-called-on-a-control-until-the-window-handle-has

I don't know what happened, but after minimizing all windows and focusing only on the installation dialog, it somehow let me thru the installation process.  I clicked back and forth the main installation window and the modal status window and somehow, I was able to successfully install my Management Studio 2008.

Reason that I installed the Management Studio 2008, was due to the fact that I cannot manage my data with editable results if I'm accessing MS SQL 2008, thru Management Studio 2005.  It is stated in some forums, that you can use higher versions of Management Studio, but cannot use lower versions to fully use the latest MS SQL version.  It does make sense to me, backwards compatibility only.

Here is the link to the MS SQL 2008 Management Studio Express installer: http://www.microsoft.com/en-us/download/details.aspx?id=7593

It states, express version, but I haven't notice any difference with the one included with the Enterprise edition installer. By the way, they both have bugs during installation, that is why I resorted in installing an express edition, even though I have an enterprise installer of MS SQL 2008.

You may have to install the SP 1 (service pack 1) of MS SQL 2008 after installation of Management Studio 2008. As indicated, during or initial install of Management Studio.