The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > Web Programming, Web 2.0 and Mashups
.
google unix.com



Web Programming, Web 2.0 and Mashups Discuss Web Programming and Web Server Administration, including LAMP, Apache, MySQL, Flash, HTML, SEO, Mashups and other Web APIs and topics.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
view HTML file through browser thepurple SUN Solaris 3 03-16-2009 10:59 AM
How can I see current browser requests? (Firefox on Ubuntu Linux) ropers UNIX Desktop for Dummies Questions & Answers 7 08-27-2008 08:33 AM
Customize your Firefox browser with Personas iBot UNIX and Linux RSS News 0 04-14-2008 04:20 AM
Firefly extension turns Firefox into a file browser iBot UNIX and Linux RSS News 0 03-31-2008 04:30 AM
Need Shell script for getting Firefox Browser Version kjannu UNIX for Dummies Questions & Answers 2 06-27-2006 11:23 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-22-2009
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,680
Add HTML Based on Browser Width (Firefox)

Here is a bit of code I wrote that includes some HTML (table and image code) based on the width of the browser. It works in Firefox. I am not sure if it works for IE. (Need to test.)

javascript Code:
  1. <script type="text/javascript"><!--
  2. var winWidth = window.innerWidth;
  3. if (winWidth > 750) {
  4. document.write('<td><img src="http://www.yourdomain.com/images/yourspace.jpg"></td>');
  5. document.write('<td><img height="280px" src="http://www.yourdomain.com/images/yourimage.jpg"></td>');
  6. }
  7. //-->
  8. </script>


---------- Post updated at 04:34 ---------- Previous update was at 04:27 ----------

Update: Does not work in IE, only Firefox so far. (Have not tested in Opera).

---------- Post updated at 04:49 ---------- Previous update was at 04:34 ----------

Ha! Seems like window.innerWidth is supported on most browsers EXCEPT IE according to this site:

W3C DOM Compatibility - CSS Object Model View

To compensate for IE, we need something like:

javascript Code:
  1. var winWidth = 0;
  2.   if( typeof( window.innerWidth ) == 'number' ) {
  3.     //Non-IE
  4.     winWidth = window.innerWidth;
  5.   } else if( document.documentElement && document.documentElement.clientWidth ) {
  6.     //IE 6+ in 'standards compliant mode'
  7.     winWidth = document.documentElement.clientWidth;
  8.   } else if( document.body && document.body.clientWidth ) {
  9.     //IE 4 compatible
  10.     winWidth = document.body.clientWidth;
  11.   }

Last edited by Neo; 10-04-2009 at 04:04 PM.. Reason: added highlight=javascript bbcode tags
Reply

Bookmarks

Tags
javascript, window.innerwidth

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0