Friday, 1 October 2010

5.Week 9

Dear Diary,

Browser compatibility is the bane of my life.

Working on the upload system atm for SilverstreamTV . Uploading works fine, had a few teething issues as i have stated in previous posts. I am currently working on deploying and developing the system on a live server which is quite a big deal bare in mind 3 months ago i didn't know how to code javascript or php. let alone combine it with as3, html, css and mysql.

So after developing the...upload widgets i am now using their original upload system to create an up to date easier to use and hopefully more aesthetically pleasing uploading and modifying tool.

The past few days i have been working on the database submissions and edit section. The issue came about when trying to upload a new thumbnail. The thumbnail generator takes in the video name via ExternalInterface:

  var flashvariable = window.document.swfid;
   flashvariable.changeText("hello" + orvariablename);
  window.location ="#";

this sends the variable (which would be my video name) to the thumbnail generator which would kick start the widget.

you may think whats the issue....well I'm not using a button in my edit page, i need the thumbnail generator to load when the page loads, so it needs to insert the variable straight away....i thought it was an easy onload function. Well different browsers deal with code differently i don't know the ins an outs of it. But i had to test each browser with different solutions. 

window.onload worked fine in IE, Opera and Navigator.


so we are left with Firefox, Chrome and Safari.....and also you need to get javascript to find out which browser the visitor is using.

if you check for safari before you check for google chrome, it will  for some reason result in an alert saying your using safari (if you enable the alerts) (see below) but this is how i got it to work.

window.onload function cross browser Internet Explorer, Firefox, Safari, Opera, Chrome and lets not forget Navigator....


// detect browser and act accordingly
           
            if (navigator.userAgent.indexOf("MSIE") != -1) {
                //alert("You are running Microsoft Internet Explorer.");
                window.onload=chosenFunction; // IE Works
            }else if (navigator.userAgent.indexOf("Firefox") != -1) {
                //alert("You are running FireFox.");
                if (document.addEventListener) // Firefox Works
                {
                document.addEventListener("DOMContentLoaded", chosenFunction, false); // Call chosenFunction in     Firefox
                }
            }else if (navigator.userAgent.indexOf("Navigator") != -1) {
                //alert("You are running Netscape.");
                window.onload=chosenFunction; // Navigator works
            }else if (navigator.userAgent.indexOf("Opera") != -1 ) {
                //alert("You are running Opera.");
                window.onload=chosenFunction; // Opera Works :)
            }else if (navigator.userAgent.indexOf("Chrome") != -1 ) {
                //alert("You are running Chrome.");
                setTimeout(chosenFunction, 300); // Google Chrome Works:)
            }else if (navigator.userAgent.indexOf("Safari") != -1 ) {
                //alert("You are running Safari."); // Safari Works
                setTimeout(chosenFunction, 500);
            }else {
                alert("You are running some odd-ball browser.");
            }


function chosenFunction(){
 // do stuff
}


So now i have done the "not as easy as it should have been" thumbnail editor... i am now free to continue with the upload system...... wish me luck!

No comments:

Post a Comment