473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Setting an Image based on viewer's screen resolution

mikek12004
200 100+
I want to load a different swf in PHP based on the viewer's screen resolution. All would be fine if I could get the screen resolution in a variable in PHP. Problem is that after I done a bit of a digging that this can be only done through javascript(or so most claim) and to pass the resolution from javascript to PHP you would need to refresh the page again (to put the resolution in the URL or in a coockie) The other solution is to use ajax and invoke the function with the onload event of the body, and in the called PHP script to save the res in a session (and latter retrieve it from that session in the main PHP code).
That's all I could fine, any idea? I would like to avoid refreshing the page
Sep 11 '08 #1
6 3004
acoder
16,027 Expert Mod 8TB
Yes, Ajax it'll have to be. For the screen resolution, use the Screen object.
Sep 11 '08 #2
mikek12004
200 100+
Found a better solution place the displayed flash in a <span> tag and then with a javascript compare the scrren resolution in an if, use a getelement by id to get the id of the span and then replace the flash inside of the <span> with another with innerHTML property if the resolution is too high, I tried the above with some text but didn't work any ideas how I can implement the aboe setup?
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
  4.  
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">
  6. <title>Untitled Document</title>
  7. </head>
  8.  
  9. <body>
  10. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  11.   <tr>
  12.     <td>
  13.     <SCRIPT language="JavaScript">
  14. <!--
  15. if ((screen.width>=1024) && (screen.height>=768))
  16. {
  17.  document.write('1');
  18.  var ni = document.getElementById('city');
  19.  document.getElementById("city").innerHTML="Mike" ;
  20. }
  21. else
  22. {
  23.    document.write('2');
  24. }
  25. //-->
  26. </SCRIPT>
  27.  
  28.     <span id='city'>Mike here</span>
  29.  
  30.  
  31.  
  32.     </td>
  33.  
  34.  
  35.   </tr>
  36.  
  37. </table>
  38.  
  39. </body>
  40. </html>
  41.  
  42.  
Sep 12 '08 #3
mikek12004
200 100+
OK when I put the script AFTER the span it worked fine but why?
Sep 12 '08 #4
acoder
16,027 Expert Mod 8TB
Because you were trying to access an element before it appears on the page.
Sep 12 '08 #5
mikek12004
200 100+
OK same setup with above I have table with a flash inside it and depending the width of the flash the table will increase in width or decrease I know how get the screen resolution woth javascript but how can I based on this value load the appropreate flash?
Sep 30 '08 #6
acoder
16,027 Expert Mod 8TB
I would recommend SWFObject for all Flash loading using JavaScript.
Sep 30 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Markus Mohr | last post by:
Hi, everyone, I have a special problem: For every monitor resolution in 200 pixel steps from 800 to 1600 pixels I have an image to be shown as centered background-image. Those images all...
3
by: Ryan Sullivan | last post by:
I have been struggling mightily in getting this to work with the scripts I have seen. I have an image map that uses overlib to display information about a school's campus: ...
11
by: Stephane D'Alu | last post by:
Do you know if it is possible to have an image to be scalled to a maximum width/height, but with keeping its aspect ratio. The two ideas I had were: - <img src="toto.jpg" style="max-width:...
2
by: John Fryatt | last post by:
Hi, Before I go on, let me just say I'm fairly new at this so excuse me if I say the wrong thing or use the wrong term. Anyway, what I am trying to do is to set up something where I can have a...
14
by: Roger Withnell | last post by:
How to I find out what size text the browser is set to? Thanks in anticipation.
3
by: Andy Baxter | last post by:
I have an image scrolling in a viewport for a panoramic image viewer. The viewport can be resized to several set resolutions so people can adjust the size according to their bandwidth. There are...
3
by: =?Utf-8?B?SlIx?= | last post by:
I would like to add text to an image. I have tried to use DrawString and it works on some images but on others it is very very small. I am pretty sure it has something to do with the size of the...
0
by: srini | last post by:
Hi, I have an application in which it shows links on left frame and images on right frame. I am calculating the image height and width to fit to the client's window dynamically based on the...
1
by: nasima khan | last post by:
Hi, i am nasima. I have got a code for setting the screen resolution of my page, but i am unable to understand. Can any one give a complete data explanation of the below code. Sub ChangeRes(X...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.