/    Sign up×
Community /Pin to ProfileBookmark

JS/PHP IE warning

Not so much a question, I’m looking more for opinions.

I’ve been trying to rack my head around a generic warning that could have adaptable reason and width variables when a user is using Internet Explorer to view a page. I ended up with this.

[b]Page[/b]

[code=php]<?php
include “ie.php”;
?>[/code]

[CODE]<SCRIPT TYPE=”text/javascript”>
<!–
if (navigator.appName == “Microsoft Internet Explorer”){ document.writeln(‘<?php echo “”.ie(85, ugly).””; ?>’); }
// –>
</SCRIPT>[/CODE]

[b]ie.php (included)[/b]

[code=php]<?php
function ie($width, $reason){
if($reason == ‘ugly’){ $reas=”This page is truly, truly, truly, truly, truly (etc.) hideous on Internet Explorer”; }
$display=”<br><table border=1 bordercolor=#000000 cellpadding=2 cellspacing=0 class=warn width=”.$width.”%><tr><td class=warn align=center>”.$reas.”. We implore you to use a proper browser when viewing this page, as your face will fall off otherwise.<p><a href=http://www.mozilla.org/><font color=lime>Mozilla Firefox</font></a></td></tr></table>”;
return $display;
}
?>[/code]

It all works fine and I’m pleased with the result, especially as IE makes such a mash up of the content of the page, but what do you guys think?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@atuchJul 16.2008 — What I usually do is create a CSS file specifically for IE hacks and use HTML conditional statements to include it. With IE at about 80% of the browser market share, its not worth the risk of losing that many users even if they are using a browser that is total junk. Most of the problems with IE are related to IE's incorrect implementation of the Element Box model (basically calculating width incorrectly). This IE specific CSS would basically just override the standard CSS and fix its elements widths and other problems in IE.
Copy linkTweet thisAlerts:
@ZnupiJul 16.2008 — How I'd do it:
[code=html]<SCRIPT TYPE="text/javascript">
<!--
if (window.ActiveXObject){ document.writeln('<?php echo ie(85, 'ugly'); ?>'); }
// -->
</SCRIPT>[/code]

You don't really need to have those "" around the ie function call. Even better, without javascript:
[code=html]<!--[if IE]>
<?php echo ie(85, 'ugly'); ?>
<![endif]-->[/code]


...as your face will fall off otherwise.[/QUOTE]
Lol! ?


Anyway, as atucn said, it's best to make your site look at least "O.K." in IE, too. Using separate stylesheets and scripts and whatever necessary.
Copy linkTweet thisAlerts:
@AlmondJul 16.2008 — I've been using this script:

[code=php]
<?php
if (eregi("MSIE",getenv("HTTP_USER_AGENT")) ||
eregi("Internet Explorer",getenv("HTTP_USER_AGENT"))) {
echo '[B]Message that IE users would see or a different piece of coding, eg: ie.css[/B]';
} else {
echo 'Message other browsers would see eg: Firefox/Opera.';
}
?>
[/code]
Copy linkTweet thisAlerts:
@TheSkyOrBustauthorJul 16.2008 — Thanks for the help guys, I'll try out what you each suggested.

At about 4 in the morning I remembered conditional comments and I was able to suit the page to meet IE's capabilities, and I found I no longer needed the message. Despite this I'll keep the code because you never know when it might come in handy.
×

Success!

Help @TheSkyOrBust spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...