PDA

View Full Version : how to ??



jr_yeo
07-06-2006, 04:54 AM
how to browser detect using javascript and/or php so that if my browser is IE this:


<select name="dynamicselector2" size="2" onChange="generateimage(this.options[this.selectedIndex].value)">

will look like


size="1"

and if my browser is not IE


size="2"


tnx :P

Twey
07-06-2006, 12:49 PM
Style your element with CSS.

jr_yeo
07-07-2006, 02:44 AM
how do i do that? :P from what i understand of CSS its still somewhat static. if m using IE i will change the size in the CSS by 1 and if m using other browsers that is not IE i will change the size in the CSS by 2 :P can't i do it dynamically? something like if browser = IE then size = 1 else size = 2.

i know the logic but not how to put it into script itself :D

DimX
07-07-2006, 11:21 AM
PHP could be something like that:

size="<?php echo strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") != false ? "1" : "2"; ?>"

Twey
07-07-2006, 01:34 PM
i know the logic but not how to put it into script itself :DEasiest way to implement this here is the !important bug.

!important ought to cause any rules that would override the rule it's applied to to be ignored, unless they are also !important. However, IE ignores it, so we can do things like this:
select {
height: 1.2em !important;
height: 2.4em;
}
DimX: There are two problems with your code. Firstly, you've got the 1 and the 2 completely the wrong way around. :p Secondly, strstr (http://www.php.net/strstr)() can return 0, which will evaluate as false when using type-converting comparison (== and !=) and thus give you an incorrect result. Instead, you must use strict comparison (=== and !==), which will not perform type conversion.

jr_yeo
07-07-2006, 02:55 PM
Twey: ur script ddnt solve exactly my problem :P DimX's script solves it exactly with !== or != i dont see the difference :D

tnx for the help guyz

Twey
07-07-2006, 03:07 PM
DimX's script solves it exactly with !== or != i dont see the differenceI explained the difference above :)

Twey: ur script ddnt solve exactly my problemIt was an example :)

jr_yeo
07-07-2006, 03:26 PM
even if i use the !== or the !=, the result that im aiming for is still the same :P
this is what i meant by i dont see the difference :D

Twey
07-07-2006, 03:40 PM
Ah, but if "MSIE" appears at the beginning of the UA string, then using !=, that script will detect the browser as not being IE :)

Plus, the user agent string is not necessarily a reliable indicator of the browser. If you looked for "Mozilla," for example, you'd find it in every IE browser's UA string since IE3, I think. Also, some browsers (and firewalls, and a couple of pieces of malware) change or strip the User-Agent header, user intervention aside.

jr_yeo
07-07-2006, 03:44 PM
tnx for the 411 :D

jr_yeo
07-23-2006, 11:13 AM
follow up question :p
is


size="<?php echo strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") != false ? "1" : "2"; ?>"
same as


size="<?= strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") != false ? "1" : "2"; ?>"
? :D tnx :p

Twey
07-23-2006, 01:14 PM
No, the latter won't work. You mustn't use a semicolon with the <?=VALUE?> syntax.

jr_yeo
07-23-2006, 02:30 PM
but when i try to remove the semicolon, the whole


size="<?= strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") != false ? "1" : "2"?>"
is not being parsed in FF :D

Twey
07-23-2006, 02:41 PM
Probably you don't have short tags enabled. The browser doesn't make a difference, by the way.

jr_yeo
07-23-2006, 02:59 PM
Probably you don't have short tags enabled
checked the phpDOTnet said the same thing :p i should have enable my short tags :D he he tnx :p which i did enable as of this moment

Twey
07-23-2006, 03:05 PM
And that, folks, is why you should never use short tags when writing code for other people. :)

jr_yeo
07-25-2006, 01:48 AM
is there a way to randomize the pictures using the getpics.php script? :p
also is there a way to sort of toggle it to sort of turn random on or off? :D tnx :p

Twey
07-25-2006, 01:57 AM
Please link.

jr_yeo
07-25-2006, 02:37 AM
sorry :( wrong thread :(

Twey
07-25-2006, 12:31 PM
Lol :D