FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


does javaScript code runs on selected browsers?





cyberbuddy
i have seen that some javasripts does work with Internet Explorer but may noot work in mozilla Firefox.
whats the exact cause .andwhy such thing happen .I have witnessed myself pitting some script in my web page and it does work in Mozilla but not in Internet explorer!!!i have tried many times but still ....some scripts work any one browser but may not work in other! Very Happy

thank u
Marcuzzo
thats easy.

JavaScript is an interpreted scripting language and therefor it has a host that interprets the source and executes it.

there are several types of Javascript, dialects if you will.
for instance Microsoft likes to call their version JScript and the newer version JScript.NET.

you are dealing with JScript on 2 occasions (I think)
1. Windows Scripting Host which is executed by WScript.exe .
2. Internet Explorer (any version)

everything else should be real Javascript Laughing
tocapa
Microsoft, Mozilla, Opera, Apple, etc. develop their Javascript interpreters separately from one another. While there are standards, they are not all adhered to perfectly. In many cases, what will work in most browsers (Firefox, Opera, Safari) will not work in Internet Explorer, because of the way Microsoft has designed JScript.

A lot of websites have information on the differences, and how to do in Internet Explorer what you already have working in other browsers.
SonLight
Javascript capabilities can be quite dramatically different from one browser to another.
A couple of references are:

http://www.webreference.com/js/column6/

http://www.quirksmode.org/js/intro.html

From the second reference, an overview of how Javascript works::

Quote:
JavaScript is most commonly used as a client side scripting language. This means that JavaScript code is written into an HTML page. When a user requests an HTML page with JavaScript in it, the script is sent to the browser and it's up to the browser to do something with it.


About incompatabilities:

Quote:
When a user receives a page which includes JavaScript, the JavaScript interpreter of his browser kicks in and tries to execute the script. Now the main problem here is that the various browsers each use their own interpreter, and that sometimes browser vendors have chosen not to implement a bit of JavaScript. Their reasons were usually related to business advantage over the competitors.

Hence the feared browser incompatibilities.

In addition each new browser version understands more JavaScript and allows more and more parts of the HTML page to be changed by scripts. This leads to even more incompatibilities.

It’s best to solve compatibility problems on a case–by–case basis. In fact, most pages on this site have been written precisely because of browser incompatibilities.


In some cases, you need to determine what capabilities a given browser has in order to send it the javascript commands which will work on that browser. The second site recommends tests to detect the presence of specific object types, rather than general version or browser name tests. They have another page which explains that further:

http://www.quirksmode.org/js/support.html

An example of the method from that page is:

Quote:
Instead, we simply look if the browser supports the object (method, array or property) we want to use. Let’s continue with the mouseover example. This script relies on the document.images array, so first and foremost we'll have to detect if the browser supports it. This is done by
if (document.images)
{
do something with the images array
}

Now you have a fail safe method of seeing if any browser can handle mouseovers. The if-statements checks if the array document.images exists. If it does (document.images) is true and the script is executed. If the images array doesn't exist it becomes false and the script is not executed.
jsfdan
JavaScript (the basics), essentially, runs on all browser which have it enabled.

BUT! JavaScript codes may not work on some browsers.
rockacola
jsfdan wrote:
JavaScript (the basics), essentially, runs on all browser which have it enabled.

BUT! JavaScript codes may not work on some browsers.


And this is when Javascript Frameworks kick in Laughing
no more browser and version check, no more redundants~
CosmicDisturbance
There's probably browser checks and if it's a certain browser, it will kill the script or something of that sort.
riccopt
the best thing to do is to avoid javascripts... specially if you can do the same thing using CSS or server side programming languages...
kacsababa
Ofcourse, build everything in layers and independent. Not categorically MVC design pattern, but thats a good start, something similar.
Marcuzzo
riccopt wrote:
the best thing to do is to avoid javascripts... specially if you can do the same thing using CSS or server side programming languages...


I disagree.
server-sided scripting can do a lot for you, but not everything.
CSS can style your page, final. sure, you can build an entire CSS menu, but you can't create stuff with it.
you will almost always require the assistance of client-sided scripting.
and you can perfectly write a crossbrowser script, so I don't see any reason to avoid Javascript.
brokenadvice
I have found that 90% of the time when a script is not working in one browser, but is working in another that there is an error in the script. Granted there are some incompatibilities, but most can be worked around.
Hogwarts
Marcuzzo wrote:
you will allmost allways require the assistance of client-sided scripting.


That is one of the most ignorant and incorrect comments I've ever heard. Allso, it's spelt almost and always.


JavaScript should be added after the completion of everything else, because otherwise people get carried away with it and end up making terribly coded websites like the almighty MySpace.

Several of my websites don't use JavaScript and are absolutely fantastic to use due to the incredibly light-weight footprint of the page (no images, 100% CSS2 + CSS3). Yes, in the next version of my SVN, I have added JavaScript -- but that's just as an on-the-top luxury for minor features (i.e. enabling a tab-key in the textareas).

Personally, I'd say that you should avoid JavaScript like the plague until you have a completely functional website completed. Otherwise we end up with "MySpace Syndrome" resulting in a terminally-failed site Sad
riccopt
Marcuzzo wrote:
riccopt wrote:
the best thing to do is to avoid javascripts... specially if you can do the same thing using CSS or server side programming languages...


I disagree.
server-sided scripting can do a lot for you, but not everything.
CSS can style your page, final. sure, you can build an entire CSS menu, but you can't create stuff with it.
you will allmost allways require the assistance of client-sided scripting.
and you can perfectly write a crossbrowser script, so I don't see any reason to avoid Javascript.


what do you mean when you say I can't create stuff with CSS?
what can you create with JS? games? Fancy effects on the sites?

once I did a fancy site using JS and CSS... the result was that I had to redo everything so that people would access the site faster...

fact: I have almost 30% of the surfers on my sites with JS disable on their browser.

for example:
here is a site that uses JS for you to select the category you want to submit to: http://www.esyndicat.com/demo/suggest-listing.php?id=0
but you could simply have used a DROPDOWN MENU to do that...

almost all the things people use JS for can be done on the server side...

unless you want to add some fancy effects like LIGHT BOX and such...

you can do form verification on the server side... no need to add JS on forms...
Marcuzzo
riccopt wrote:

what do you mean when you say I can't create stuff with CSS?
what can you create with JS? games? Fancy effects on the sites?


you can't create HTML elements with CSS, yes, you can hide and show them... but that is not the same.
with PHP....sure, you can just send stuff to the server and make a php script echo new HTML code.
30% has js turned off... howmany people are still on smallband?

and for games and fancy effects...I would use flash
to create menus I would use CSS and to check forms I would also use PHP.

I only use Javascript to modify the DOM at runtime and to perform simple tasks.
Code:

<html>
<head>
<script type="text/javascript">
function somefunc(){
var div = document.createElement("div");
div.style.position = "absolute";
div.style.border = 2 + "px solid gray";
div.style.top = 60 + "px";
div.style.left = 100+"px";
div.style.width=500+"px";
div.style.height = 360 + "px";
div.innerHTML = "try doing this server-sided";
document.getElementsByTagName("body")[0].appendChild(div);
}
</script>
</head>
<body>
<a href="javascript:somefunc();">this is what I mean</a>
</body>
</html>


try doing this without reloading the page or without sending stuff to a server.(notice the content of the body tag... no hidden div)

and stop flaming people
Hogwarts
Marcuzzo wrote:
try doing this without reloading the page or without sending stuff to a server.

and stop flaming people


If you don't have a graceful fall-back to that, your site is going to end up with MySpace-quality code.

Marcuzzo wrote:
and you can perfectly write a crossbrowser script, so I don't see any reason to avoid Javascript.


Maybe it's because JavaScript, unless you're writing a completely JavaScript-based site, should be used only as an additional level after everything else is completed?
riccopt
double posted!
riccopt
Marcuzzo wrote:
riccopt wrote:

what do you mean when you say I can't create stuff with CSS?
what can you create with JS? games? Fancy effects on the sites?


you can't create HTML elements with CSS, yes, you can hide and show them... but that is not the same.
with PHP....sure, you can just send stuff to the server and make a php script echo new HTML code.
30% has js turned off... howmany people are still on smallband?

and for games and fancy effects...I would use flash
to create menus I would use CSS and to check forms I would also use PHP.

I only use Javascript to modify the DOM at runtime and to perform simple tasks.
Code:

<html>
<head>
<script type="text/javascript">
function somefunc(){
var div = document.createElement("div");
div.style.position = "absolute";
div.style.border = 2 + "px solid gray";
div.style.top = 60 + "px";
div.style.left = 100+"px";
div.style.width=500+"px";
div.style.height = 360 + "px";
div.innerHTML = "try doing this server-sided";
document.getElementsByTagName("body")[0].appendChild(div);
}
</script>
</head>
<body>
<a href="javascript:somefunc();">this is what I mean</a>
</body>
</html>


try doing this without reloading the page or without sending stuff to a server.(notice the content of the body tag... no hidden div)

and stop flaming people

how many people are still on smallband? -> 0% are on smallband... (unless you consider cellphones as smallband)... also since most of my sites are PORN I recommend all the surfers to tunr JS off to avoid malicious codes that are found on lots of sites... (actually I recommend them to SWITCH TO FIREFOX and to install the NOSCRIPT plugin)

and what is the idea of using such thing (talking about that script? (for me that is fancy - unless it is to display some relevant info for an specific user... and for that you sould combine some server side script to load the data from some DB)
I use JS... but I try to limit it to things that will work even if people have JS disable on their sites...

if someone had JS disable they will never be able to see that result...

there was a time that whenever we wanted to use HOVER effects we needed to use JS... there was a time when all pages had white BG, Blue Links (that when clicked became purple), and black text... and tables were one of the hottest things that could be used...

now we can even float images to the left and to the right...

JS is for fancy things... and should be avoided as much as possible...

www.artinsurf.com is an example of site I made that uses JS to display the pictures on the galleries and that works even if the JS is disable (the images will load on the page you were)... not that the random images on the index pages doesnt use JS... everytime you load the page new images will open (that is also fancy... but works on all broswers)...


ALSO: I am not flaming anyone... I am simply against JAVA SCRIPTS that are used on unnecessary places where other solutions that are SERVER SIDED could be used...
Marcuzzo
riccopt wrote:
how many people are still on smallband? -> 0% are on smallband... (unless you consider cellphones as smallband)... also since most of my sites are PORN I recommend all the surfers to tunr JS off to avoid malicious codes that are found on lots of sites... (actually I recommend them to SWITCH TO FIREFOX and to install the NOSCRIPT plugin)


1. you would be amazed. my ISP provides FREE smallband internet for those that take a landline. and lots of "older" people do take that option because they don't really spend a lot of time on the internet and don't need a lot of bandwidth or speed.

2. so you advise people to turn OFF javascript for your and pornsites of others to avoid malicious code... do I really need to add something to it?

3. really, I don't see why the noscript plugin needs to be installed on Firefox.
maybe I'm a noob or just plain simple ignorant.
As far as I know javascript could only harm your machine when you are running on a WINDOWS host and using IE as a browser.
this because you can access the system using the "ActiveXObject" object.
like so:
Code:
<html>
<head>
<title>Javascript or JScript</title>
<script type="text/javascript">
 window.onload = function () {
      (  typeof(ActiveXObject) == "function"  ) ? alert("You are running on IE and the script will create 2 objectes to test"): alert('NOT running on IE \n the script will FAIL after this message');
      var wShell = new ActiveXObject("WScript.shell") ;  // WScript Shell Object... IE only!!!
      alert(typeof(wShell)); // shows "object" if succesfully created
      var fso = new ActiveXObject("Scripting.FileSystemObject"); // FileSystem Object... IE only!!!
      alert(typeof(fso));// shows "object" if succesfully created
    }
</script>
</head>
<body>
</body>
</html>


I'm running on a linux distro, so Firefox by default, the NOSCRIPT plugin is NOT installed on my browser. and I'm not worried about dodgy javascript code.
and for those that DO use IE... the "browser" will alert you if ActiveX is beeing accessed and it is just a judgement call to allow it or not.

and finally: 4
riccopt wrote:
against JAVA SCRIPTS that are used on unnecessary places where other solutions that are SERVER SIDED could be used

I couldn't agree more, like I said before.
Quote:
I only use Javascript to modify the DOM at runtime and to perform simple tasks.

read before you flame...

to conclude this endless and ridiculous discussion:

IE >>> JScript.
mozilla and other >>> javascript.

if there was something that you might want avoid, it would be JScript and not javascript.
infact, if we are recommending anyway, I would recommend not running on IE or Windows at all.
but that is another matter.

I'm through with this topic, take care Wink
pollux1er
Such situations are very annoying. Because if you are through building a website (while building it you were testing preview on only one browser), and you find that the reslut is not the one you were expecting, you will have to review all your codes only because of browsers.
I almost always have that problem because I am too much working with Mozilla instead of Internet Explorer which is the most used browser(I suppose).
Related topics
Tutorial: Image Rollovers w/ Javascript
Java tutorials
AJAX tutorial [2nd part now updated]
How? : Javascript Select All [solved]
AJaX or ASPX?
Changing internal data with scripting.
Hide Email Address With Javascript - Worth It?
Why does this code make undeletable files?
embedding javascript menu simple problem
how to hide Javascript code into GIF Image?
Awesome javascript tricks!
(Unsolved) Malicious Javascript Code
Zaphod — Mozilla’s new experiment, a JavaScript engine writt
How does this page work without javascript?
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.