HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
image resize... conditional
Post new topic   Reply to topic    HTML Help Forum Index -> Javascript
View previous topic :: View next topic  
Author Message
Jazeker



Joined: 12 Feb 2005
Posts: 2

PostPosted: Sat Feb 12, 2005 12:31 pm     image resize... conditional Reply with quote

Hi,

Wondering whether there's a simple html trick that can help me : I have a page with an image. The image should just show at it's original size, unless it 's bigger than the browser screen... in that case it should be resized to fit the window again.

Is there a way to let html do this ? If not, is there some simple javascript that does such things ?

thx
chrisxkelley



Joined: 07 Dec 2004
Posts: 246

PostPosted: Sat Feb 12, 2005 12:56 pm     Reply with quote

there is no way to do this using html...

however, you can build in javascript a sniffer that detects the page size, then based on that redirects them to a page that will fit their resolution. It's kind of a painful way of getting around that problem, because you would have to make 3 different websites with different sizes.... if you dont want to do that just make your page compatible for 1024x768 and most people wont have a problem with it.

but if you want that javascript code let me know, its not too hard to write
Jazeker



Joined: 12 Feb 2005
Posts: 2

PostPosted: Sun Feb 13, 2005 7:20 am     Reply with quote

chrisxkelley wrote:
there is no way to do this using html...

however, you can build in javascript a sniffer that detects the page size, then based on that redirects them to a page that will fit their resolution. It's kind of a painful way of getting around that problem, because you would have to make 3 different websites with different sizes.... if you dont want to do that just make your page compatible for 1024x768 and most people wont have a problem with it.

but if you want that javascript code let me know, its not too hard to write


Hey chrisxkelley,

You would do me a big favour with such code. I hope it's very cross-browser compatible though. It is not a problem to let the JS call another page, because in fact, the page will be generated by a Perl/CGI script (now that's my area Wink ) which can generate a new page where the image has a width = "100%" property or something like that. The problem is that when I do that right away, small images would be blown up and that would look terrible... hence the need to check when images are way out of line.
chrisxkelley



Joined: 07 Dec 2004
Posts: 246

PostPosted: Mon Feb 14, 2005 11:22 pm     Reply with quote

sure... do something like this...

Code:

<script language="text/javascript">
<!--
if(screen.width>=1280||screen.height>=1024){
var sTargetURL = "bigscreen.html";
}else if(screen.width=1024||screen.height=768){
var sTargetURL = "normalscreen.html";
}else if (scren.width<=800||screen.height<=600){
var sTargetURL = "smallscreen.html";
}else{
var sTargetURL = "normalscreen.html";
alert("Your current resolution settings do not match the content of this page.  Your current resolution is "+screen.width+" by "+screen.height+".  If possible please change your resolution to either 800x600, 1024x768, or 1280x1024.");
}

function doRedirect()
{
    setTimeout( "window.location.href = sTargetURL", 500 );
}

//-->
</script>

<body onload="doRedirect()">

if i got all that correctly, what it should do is check the resolution, if it is 1280x1024 or higher, it will redirect to bigscreen.html. if it is 1024x768, normalscreen.html, and if equal to or less than 800x600, smallscreen.html. If the user has a resolution somewhere in-between those three then it will politeley send an alert telling them that their resolution is different than what is best for the page, and ask them to change to one of the three choices.

what you need to do, is make those three pages, and put the function "doRedirect()" in the onLoad of your body tag.

phew. forgive me if i screwed up, it's 11:30 and i'm taking a break from my algebra 2 homework Shocked ...haha

cheers,
chris
chrisxkelley



Joined: 07 Dec 2004
Posts: 246

PostPosted: Mon Feb 14, 2005 11:28 pm     Reply with quote

aso, i forgot to mention that if the user has wierd screen resolution, the page it will take them to is the one meant for 1024x768, but this can be changed easily.


and i'm moving this topic to the "other lnguages forum" Exclamation
Talonkarrde



Joined: 19 Feb 2005
Posts: 1

PostPosted: Sat Feb 19, 2005 8:04 am     Reply with quote

Muchos helpful.

So the question is:

Suppose I have a website, and the first thing that loads is index.html.

I guess the script should go in index.html, and then I would have smallindex.html, bigindex.html, and normalindex.html, as three sites that basically have the same thing; but are formatted differently?

The 3 indecies only have lines of frame coding, so that would work, correct?
optikool



Joined: 31 May 2005
Posts: 1
Location: Bay Area California

PostPosted: Tue May 31, 2005 11:10 am     image resize... conditional Reply with quote

Hi 1 other thing you can try is.... if all you want to do is resize an image that you placed on your web site, like for example a picture of your cat, you can go into your Web browser options and make sure Enable Automatic Resizing is checked. You probably don't want to have the size pre specified in your html code.

Hope that helps...
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> Javascript All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial