I'm currently developing a page that detects the users screen res and browser version(this code was in the body section so ran when ever a page loaded). If they are not of an acceptable standard a document.write function displays a message warning. When I had my javascript in the html file this worked fine.
I placed the javascript in the right position on the page so that when it ran the document.write it put the warning message in the right place on the page.
I now want to make it so my javascript is in an exsternal file. I saved the code in a .js file, I linked to the .js file in the <head> and now I have no idea how to make it so the code runs when the page loads and puts the document.write messages in the right place.
My .js file:
function checks(){
var browserver = navigator.userAgent.toLowerCase();
alert ("Hello, I am coming from and external javascript");
//This if selector looks to see if the "useragent" (version) contains the string "msie 6" if it does it is IE6
if
(
browserver.indexOf('msie 4')!= -1 && browserver.indexOf('msie 7')== -1 && browserver.indexOf('msie 8')== -1||
browserver.indexOf('msie 5')!= -1 && browserver.indexOf('msie 7')== -1 && browserver.indexOf('msie 8')== -1||
browserver.indexOf('msie 6')!= -1 && browserver.indexOf('msie 7')== -1 && browserver.indexOf('msie 8')== -1||
browserver.indexOf('firefox/3.0')!= -1 && browserver.indexOf('msie 7')== -1 && browserver.indexOf('msie 8')== -1||
browserver.indexOf('firefox/2')!= -1 && browserver.indexOf('msie 7')== -1 && browserver.indexOf('msie 8')== -1||
browserver.indexOf('firefox/1')!= -1 && browserver.indexOf('msie 7')== -1 && browserver.indexOf('msie 8')== -1||
browserver.indexOf('firefox/0')!= -1 && browserver.indexOf('msie 7')== -1 && browserver.indexOf('msie 8')== -1
)
{
parent.document.write("<table><tr><td><img src='https://portal.durhamlearning.net/Image Library/red.gif' alt='Warning' align='absmiddle'/></td><td>The Internet browser you are using is outdated and will affect the quality of your experience. Please consult your system administrator about updating your browser.</td></tr></table>")
}
if (screen.width<1024)//This if selector detects small screen Size
{
parent.document.write("<table><tr><td><img src='https://portal.durhamlearning.net/Image Library/red.gif' alt='Warning' align='absmiddle'/></td><td> Your screen resolution is lower than the recommended minimum size of ");
parent.document.write(" 1024 pixels wide. Currently, your resolution is only set to a width of "+ screen.width + " pixels. <a href='https://portal.durhamlearning.net/Help%20Desk/Lists/FrequentlyAsked%20Questions/DispForm.aspx?ID=53&RootFolder=%2fHelp%20Desk%2fLists%2fFrequentlyAsked%20Questions%2fComputer%20Setup'>Help</a></td></tr></table>");
}
}















