...

View Full Version : Importing a css and js file when browser is NOT* IE



rlemon
10-19-2005, 09:53 PM
I've seen this done but for the life of me i can't find the example.

for obvious reasons document.write will not work. any suggestiongs or links to tutorials.

I have not a clue on how to do this. i've thought about browser detection via PHP but thats just too buggy/unreliable.

basically i have a .css and .js file that i want to include on the website ONLY when they are not using IE.

I have 'generic' code for IE but the cutom display for my form elements does not work in IE, infact it breaks the elements in IE....

felgall
10-19-2005, 11:52 PM
How are you intending to identify that the browser is IE?

What is the purpose of the non-IE code? Why doe you specifically need to single out that browser? Is there some particular functionality that identifies what you are trying to do that you can test for?

In Javascript IE on windows can best be identified by testing for if activeX is supported but that would treat IE on the Mac as a non-IE browser.

There are CSS hacks that allow code to be added that is specific to IE and IE-Mac.

rlemon
10-20-2005, 02:31 AM
How are you intending to identify that the browser is IE?

What is the purpose of the non-IE code? Why doe you specifically need to single out that browser? Is there some particular functionality that identifies what you are trying to do that you can test for?

In Javascript IE on windows can best be identified by testing for if activeX is supported but that would treat IE on the Mac as a non-IE browser.

There are CSS hacks that allow code to be added that is specific to IE and IE-Mac.

As mentioned in my origional post i have code that does not work in IE.

This is a added feature that is not needed ultimatly but does make the site look nice. I myself am not an IE user, and i plan on using the site so i wish to code it to those specs.
This does not mean that i am totally ignorant of IE users. like i said i wish to only have this code included when the browser is not ie so everyone can still use the functionality of the site.

So please, any constructive help would be appreciated.

gph
10-20-2005, 02:43 AM
for obvious reasons document.write will not work. any suggestiongs or links to tutorials.

Not that document.write is the best way to go but what do you mean by "will not work"?



if((!document.all||window.opera)&&document.getElementById)
document.write('<script src="..." type="text/javascript"><\/script><link rel="stylesheet" type="text/css" href="...">)


<edit>editing errors in code</edit>

gph
10-20-2005, 03:12 AM
Not that document.write is the best way to go
I was thinking that introducing the elements using the DOM would be better but that would require that it be done onload or after the <head>. Maybe document.write is the best way to go on the client.

glenngv
10-20-2005, 03:45 AM
I have 'generic' code for IE but the cutom display for my form elements does not work in IE, infact it breaks the elements in IE....
If we solve this problem instead, then you won't need to exclude css and script in IE.

rlemon
10-20-2005, 03:55 AM
If we solve this problem instead, then you won't need to exclude css and script in IE.

this is not worth the effort.

and document.write was not working. i was unable to get it working - don't know why.

glenngv
10-20-2005, 04:13 AM
Can you elaborate on what's happening instead of just saying "it's not working"? Can you post the code?

Bill Posters
10-20-2005, 09:22 AM
Don't bother using either js object/browser detection or CSS hacks. Use conditional comments (http://www.quirksmode.org/index.html?/css/condcom.html).

e.g.

<!--[if IE]>

<style type="text/css"> @import url(ie.css) </style>
<script type="text/javascript" src="ie.js"></script>

<![endif]-->

glenngv
10-20-2005, 09:33 AM
Use conditional comments (http://www.quirksmode.org/index.html?/css/condcom.html).

I also initially thought of that. But what rlemon wants is to include css and js when browser is NOT IE. Though in the thread title, it's the opposite. Unless there was a mistake in the content and not in the title.

Title: Importing a css and js file when browser is IE
Content:

basically i have a .css and .js file that i want to include on the website ONLY when they are not using IE.

Bill Posters
10-20-2005, 10:52 AM
My bad (and rlemon's) ;)

rlemon
10-20-2005, 03:24 PM
My bad (and rlemon's) ;)

whooops!

jmccaskill
10-20-2005, 07:20 PM
I agree with glenngv that, rather than looking for a hack to serve code to non-IE, the best thing to do is to examine what you have to see if you can make it work without a hack. That said, you could use the comment element. As far as I know, only IE supports it, though I have done NO research on this, and I very easily could be wrong. The usage would be:

<!--
here is a comment that all browsers
will regard as a comment
-->
<comment>
here is a comment that IE will regard
as a comment, but other browers will
render the contents
</comment>

rlemon
10-20-2005, 08:32 PM
I agree with glenngv that, rather than looking for a hack to serve code to non-IE, the best thing to do is to examine what you have to see if you can make it work without a hack. That said, you could use the comment element. As far as I know, only IE supports it, though I have done NO research on this, and I very easily could be wrong. The usage would be:

<!--
here is a comment that all browsers
will regard as a comment
-->
<comment>
here is a comment that IE will regard
as a comment, but other browers will
render the contents
</comment>



thankyou and i will keep that in mind. however I have just recently given up on the code i wanted to run when the browser != IE

The application is still not 100% (there is some issue with the height spacing of the footer bar) but here is the site:

had posted url but removed it, the site is an image gallery and there are alot of personal images on it. the images are not all of me so i am unsure if everyone who is on the site wants this to become public (i'm making it for work - you know, a place to post images from company events.).
Once i have replaced those images with some temporary images i will repost a link back to the image gallery.


Take a look, see what you think.

Bill Posters
10-20-2005, 09:23 PM
I agree with glenngv that, rather than looking for a hack to serve code to non-IE, the best thing to do is to examine what you have to see if you can make it work without a hack. That said, you could use the comment element. As far as I know, only IE supports it, though I have done NO research on this, and I very easily could be wrong. The usage would be:

<!--
here is a comment that all browsers
will regard as a comment
-->
<comment>
here is a comment that IE will regard
as a comment, but other browers will
render the contents
</comment>


I'm not sure introducing invalid, proprietory elements is the way to go.

felgall
10-21-2005, 12:09 AM
The way to solve this problem is to test if the browser supports a given process before running that process. That way if IE6 and NS4 don't support it but Firefox and IE7 do then it will run in the browsers that support it and not run in the browsers that don't.

This is called "feature sensing" and is much better than browser sensing as simply being able to work out what browser is being used can be hundreds of lines of code and wont recognise a browser that comes out after the code is written.

If you provide an example of a piece of code that doesn't work on IE6 I can show you how to either get it to work on IE6 or to get IE6 to ignore it but without something specific I can't provide details.

rlemon
10-21-2005, 12:44 AM
The way to solve this problem is to test if the browser supports a given process before running that process. That way if IE6 and NS4 don't support it but Firefox and IE7 do then it will run in the browsers that support it and not run in the browsers that don't.

This is called "feature sensing" and is much better than browser sensing as simply being able to work out what browser is being used can be hundreds of lines of code and wont recognise a browser that comes out after the code is written.

If you provide an example of a piece of code that doesn't work on IE6 I can show you how to either get it to work on IE6 or to get IE6 to ignore it but without something specific I can't provide details.

again, thankyou but i have given up on the code.
it was buggy in all browsers but FF and it is not worth it.

basically i had some code to create a custom layer over a dropdown (selectbox) list.

the code inserted divs and spans over the dropdown list to mask it's appearence. i have decided it would be better to just show a regular selectbox so it's ok. really.

thanks for the effort everyone, and i'll be sure to repay it if ever i can.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum