Add HTML Based on Browser Width (Firefox)

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums Web Development Add HTML Based on Browser Width (Firefox)
# 1  
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=""></td>');
  5. document.write('<td><img height="280px" src=""></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 05:04 PM.. Reason: added highlight=javascript bbcode tags
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #377
Difficulty: Medium
macOS is UNIX V7 compliant.
True or False?

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy and past html text use wrong character set - Firefox

Hello. The source code is here : WMI query to find memory slot and installed memory on each slot at post nbr 7 Looking at the text from firefox show nothing special. Then I Copy the text to notepad and make some change and save to file. Then I open the file in powershell and try to... (2 Replies)
Discussion started by: jcdole
2 Replies

2. UNIX for Beginners Questions & Answers

How to convert my /bin/sh script with cgi and html to run it on browser!??

Hello, I want to run this script on my CentOS 6 via browser : ________________________________________________________________________________________________ #!/bin/sh echo Username? read MY_NAME echo Provisional file name? read MY_FILE echo File NAME you want to save? read MY_FILE2... (16 Replies)
Discussion started by: juta2020
16 Replies

3. AIX

Mozilla firefox browser is not working

Hello, We enabled X11 and xming is riunning. we used to open firefox window using below command on AIX. /usr/bin/firefox Xclock is working fine now. But for some reason firefox stopped working on one of our AIX LPAR. Can you please look in to below error. />/usr/bin/firefox... (5 Replies)
Discussion started by: aaron8667
5 Replies

4. Shell Programming and Scripting

Fixed width file search based on position value

Hi, I am unable to find the right option to extract the data in the fixed width file. sample data abcd1234xgyhsyshijfkfk hujk9876 io xgla loki8787eljuwoejroiweo dkfj9098 dja Search based on position 8-9="xg" and print the entire row output ... (4 Replies)
Discussion started by: onesuri
4 Replies

5. Solaris

view HTML file through browser

Howdy experts, I have a HTML file in /var/tmp/file.html How can i view it through the webbrowser (mozilla or IE explorer) Thanks, purple (3 Replies)
Discussion started by: thepurple
3 Replies

6. UNIX Desktop Questions & Answers

How can I see current browser requests? (Firefox on Ubuntu Linux)

I'm not sure if this is the right forum (if there's a better forum elsewhere, then I would be grateful for any pointers), but anyway: I am using Firefox on Ubuntu 7.10 for day-to-day graphical webbrowsing. I sometimes find that some websites take a long time to answer certain requests... (7 Replies)
Discussion started by: ropers
7 Replies

7. UNIX for Dummies Questions & Answers

Need Shell script for getting Firefox Browser Version

Hi, How to write a script for finding out firefox version in our linux machine? Could you please share the same? I am using Red Hat Linux machine. Thanks, Kammy (2 Replies)
Discussion started by: kjannu
2 Replies

Featured Tech Videos