SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Load external script depending on window size

    Hello I need some quick help for a school project,

    I need a script for the head of my HTMl file that examines the size of the browser window. If the browser is a certain size, then the HTML will load a external javascript. Is this possible?

    Thank you

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First you need to get the size of the window
    Most browsers (all new browsers) use innerHeight and innerWidth
    IE uses the clientHeight and width of the body (IEg and 'quirks' mode
    or the document.documentElement (the html element)
    Code:
    function viewsize(){
    	var b= document.body, d= document.documentElement;
    	if(typeof window.innerHeight==='number'){
    		return [window.innerWidth, window.innerHeight];
    	}
    	return [Math.max(b.clientWidth, d.clientWidth),
    	Math.max(b.clientHeight, d.clientHeight)]
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •