TrainReq 06-13-2007, 11:25 AM How do I get it to where it more/less says
If the browser is IE , than run the following function
if(st.length > 2083) st = st.substr(0, 2083);
And If the browser is not IE, than dont run that above function
Philip M 06-13-2007, 11:37 AM if (document.all) {
if (st.length > 2083) {st = st.substr(0, 2083)} // length of substring to be returned
}
Arty Effem 06-13-2007, 12:52 PM if (document.all) {
if (st.length > 2083) {st = st.substr(0, 2083)} // length of substring to be returned
}Could you explain the connection between the presence of document.all and the browser being I.E.?
Philip M 06-13-2007, 01:07 PM Microsoft's Internet Explorer has a proprietary property of the document object that is called "all".
if (document.all) {
tests whether this property is present. In other words, whether the browser is IE4+.
For more info see:-
http://www.javascriptkit.com/javatutors/objdetect3.shtml
Arty Effem 06-13-2007, 01:57 PM Microsoft's Internet Explorer has a proprietary property of the document object that is called "all".
if (document.all) {
tests whether this property is present. In other words, whether the browser is IE4+.
For more info see:-
http://www.javascriptkit.com/javatutors/objdetect3.shtml
It's wrong/out of date, just like so many of the scripts available there. The presence of document.all does not identify Internet Exporer.
Try typing this into Opera's address bar: javascript:alert(document.all)
Philip M 06-13-2007, 03:07 PM It's wrong/out of date, just like so many of the scripts available there. The presence of document.all does not identify Internet Exporer.
Try typing this into Opera's address bar: javascript:alert(document.all)
Oooooooooooooo!
Well how about:-
if ((document.all) && (!window.opera)) {
if (st.length > 2083) {st = st.substr(0, 2083)} // length of substring to be returned
}
Arty Effem 06-13-2007, 04:07 PM Oooooooooooooo!
Well how about:-
if ((document.all) && (!window.opera)) {
if (st.length > 2083) {st = st.substr(0, 2083)} // length of substring to be returned
}That will test true for FX in quirks mode. Try Googling "support document.all"
Philip M 06-13-2007, 04:31 PM That will test true for FX in quirks mode. Try Googling "support document.all"
As I understand it quirks mode exists solely to facilitate backwards compatibility. New documents ought not to rely on quirks mode but should comply with standards mode.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
In fact I do not know anyone who uses Opera which has about 1.5% of the market, about the same as IE5. Also, does Trainreq want his script to work solely in IE, or in browsers which mimic IE as well.
However, it looks as though the problem can be overcome with a further tweak:-
if ((document.all) && (!window.opera) && (!window.getComputedStyle)) { //IE, not Opera, not Firefox
if (st.length > 2083) {st = st.substr(0, 2083)} // substring to be returned
}
TrainReq 06-14-2007, 12:21 AM will this work with IE6 and 7 .. cause i would like to say . If IE6 or IE7 , but not firefox or opera , do the function.
Arty Effem 06-14-2007, 12:40 AM will this work with IE6 and 7 .. cause i would like to say . If IE6 or IE7 , but not firefox or opera , do the function.
The proper answer to this question is a question: What makes you think you need to do this? If you're trying to run code that won't be supported, you need to show it.
TrainReq 06-14-2007, 12:42 AM long story why.. but I need to get it to where the code only runs if it is IE6 or 7
glenngv 06-14-2007, 02:37 AM I'm guessing it's for the maximum URL length for IE which is 2083. Other browsers has longer limit.
I think conditional compilation of jscript in IE (http://www.javascriptkit.com/javatutors/conditionalcompile.shtml) is the most suitable solution for this problem.
TrainReq 06-14-2007, 03:01 AM i dont get it. This is what i need to do ..
If IE version is IE6 or IE7 , run the function , if it is not IE6 or IE7 (like IE5 and down or firefox or opera) than dont run the function.
felgall 06-14-2007, 03:17 AM To test for IE you can test if the browser is running JScript rather than JavaScript (since IE runs JScript and other browsers run JavaScript). The following conditional code is treated as a comment in JavaScript but runs in IE.
/*@cc_on
@if (@_jscript)
alert('browser is Internet Explorer');
@end @*/
TrainReq 06-14-2007, 04:08 AM what about this
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
if(str.length > 298) st = str.substr(0, 298);
}
does that look right.. because if i go
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
alerts('you are using IE')
}
It works just fine and only alerts me in IE .. but my question is.. did i throw if(str.length > 298) st = str.substr(0, 298); in the right place.
felgall 06-14-2007, 06:56 AM All browsers can set their useragent to report themselves as Internet Explorer which automatically sets the appName to that as well.Just set all your browsers to report themselves as IE and they will.
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
alerts('you are using IE, Firefox, Opera, or some other web browser masquerading as IE')
}
Philip M 06-14-2007, 07:31 AM will this work with IE6 and 7 .. cause i would like to say . If IE6 or IE7 , but not firefox or opera , do the function.
That is not what you asked for to start with.
My latest offering is:-
if ((document.compatMode) && (document.all) && (!window.opera) && (!window.getComputedStyle)) { //IE6+, not Opera, not Firefox
if (st.length > 2083) {st = st.substr(0, 2083)} // substring to be returned
}
|