/    Sign up×
Community /Pin to ProfileBookmark

Is this code OK?

Hi guys,

I modified a JavaScript and I wondered if it is still OK.

<script language=”JavaScript”>
<!–
if (screen.width>=640)
{
window.location=”pc/index.htm”;
}
//–>
</script>

Is this code ready to use?

Thanks.

Frank

to post a comment
JavaScript

35 Comments(s)

Copy linkTweet thisAlerts:
@jbotOct 05.2004 — [i]Originally posted by Frank1984 [/i]

[B]I modified a JavaScript and I wondered if it is still OK.[/B][/QUOTE]


well done!! you must be feeling dead proud :rolleyes:

anyway, how are we meant to know if it's ready to use, since we don't know what you're trying to do. tho on the face of it, there's nowt wrang with it. so, to be frank, frank, yes i'd say it's ready

btw: was your mum a fan of Frankie Goes To Hollywood, per chance LOL
Copy linkTweet thisAlerts:
@CharlesOct 05.2004 — 
  • * With the SCRIPT element the "type" attribute is required. For JavaScript use [font=monospace]<script type="text/javascript">[/font]


  • * About one in ten users don't use JavaScript. And of those who do huge numbers don't maximize their browser windows. You would do well to make one page that works on any window size and when there is no window.


  • * If you insist on the multi page thing, make sure that you include your redirect on each page or you'll end up with linking trouble.
  • Copy linkTweet thisAlerts:
    @agent_x91Oct 05.2004 — I've been using javascript "script" tags for years, and have never included a "type" parameter in the tag. It is not required.
    Copy linkTweet thisAlerts:
    @jbotOct 05.2004 — [i]Originally posted by agent_x91 [/i]

    [B]I've been using javascript "script" tags for years, and have never included a "type" parameter in the tag. It is not required. [/B][/QUOTE]


    it is required when making your site XHTML compliant. that way the browser knows how to properly deal with it.
    Copy linkTweet thisAlerts:
    @CharlesOct 05.2004 — [i]Originally posted by agent_x91 [/i]

    [B]I've been using javascript "script" tags for years, and have never included a "type" parameter in the tag. It is not required. [/B][/QUOTE]
    Well, you've been doing it wrong since the spring of 1998. [i]From the now superseded HTML 4.0 Specification:[/i]

    [b][font=monospace]<!ELEMENT SCRIPT - - %Script; -- script statements -->

    <!ATTLIST SCRIPT

    charset %Charset; #IMPLIED -- char encoding of linked resource --

    type %ContentType; #REQUIRED -- content type of script language --

    src %URI; #IMPLIED -- URI for an external script --

    defer (defer) #IMPLIED -- UA may defer execution of script --

    >[/font][/b][/quote]
    Copy linkTweet thisAlerts:
    @Frank1984authorOct 06.2004 — [i]Originally posted by Charles [/i]

    [B]* About one in ten users don't use JavaScript.[/B][/QUOTE]


    This scares me. I ensured my client that my solution is fool-proof, but when it's right what you say it won't work with 10% of the visitors.

    Is there a language that every computer can read (except for HTML)?

    And is it really that bad to use JavaScript?

    Thanks
    Copy linkTweet thisAlerts:
    @agent_x91Oct 06.2004 — go almost anywhere on the web and you see javascript. almost every browser supports javascript. if you are unable to use javascript, you're severely limited and the most you can do for someone is point them to a browser which supports javascript inside the <noscript> tags of your page.
    Copy linkTweet thisAlerts:
    @agent_x91Oct 06.2004 — [i]Originally posted by Charles [/i]

    [B]Well, you've been doing it wrong since the spring of 1998. [/B][/QUOTE]


    well it's never caused any problems for me or any of my pages' viewers so it can't really be called "wrong"
    Copy linkTweet thisAlerts:
    @Paul_JrOct 06.2004 — [i]Originally posted by agent_x91 [/i]

    [B]if you are unable to use javascript, you're severely limited[/B][/QUOTE]

    [font=palatino linotype]Uhh&#8230; how do you figure? I can develop perfectly functional websites without using JavaScript. JavaScript is an enhancement; the functionality of your website should not depend upon it, as so many unfortunately do.[/font]
    Copy linkTweet thisAlerts:
    @agent_x91Oct 06.2004 — if javascript isn't supported, chances are almost nothing else is. there really isn't much you can do with just simple HTML.
    Copy linkTweet thisAlerts:
    @Paul_JrOct 06.2004 — [i]Originally posted by agent_x91 [/i]

    [B]if javascript isn't supported, chances are almost nothing else is.[/b][/quote]

    [font=palatino linotype]What do you mean by, &#8220;chances are almost nothing else is&#8221;? What are you referring to that won&#8217;t be supported? I, for one, have a very standards compliant browser, but sometimes I disable JavaScript to stop all those annoying things people seem to think are &#8220;cool&#8221;.[/font]

    [i]Originally posted by agent_x91 [/i]

    [B]there really isn't much you can do with just simple HTML. [/B][/QUOTE]

    [font=palatino linotype]Isn&#8217;t much you can do with just simple HTML? There isn&#8217;t much you can do [i]without[/i] HTML. That&#8217;s what a webpage is &#8212; HTML. There is nothing simple about it. Without it, you cannot build a webpage.[/font]
    Copy linkTweet thisAlerts:
    @agent_x91Oct 06.2004 — Hey I'm not saying HTML is useless, of course it's necessary for web pages - but HTML alone doesn't get you very far. using HTML without javascript or a similar scripting language is like using a toothbrush without toothpaste
    Copy linkTweet thisAlerts:
    @Paul_JrOct 06.2004 — [i]Originally posted by agent_x91 [/i]

    [B]Hey I'm not saying HTML is useless, of course it's necessary for web pages - but HTML alone doesn't get you very far. using HTML without javascript or a similar scripting language is like using a toothbrush without toothpaste [/B][/QUOTE]

    [font=palatino linotype]I fail to see how that is true. The point of the web is to deliver content. Why do you need JavaScript, or any other scripting language, to deliver content?[/font]
    Copy linkTweet thisAlerts:
    @jbotOct 07.2004 — [i]Originally posted by Paul Jr [/i]

    [B]The point of the web is to deliver content. Why do you need JavaScript, or any other scripting language, to deliver content?[/B][/QUOTE]


    this is wot a good many newbies fail to understand. JS was invented to augment the delivery of a site, but not to make the site impossible to use without it.

    yes, you can still code JS in your site to do some nice tricks, including DHTML navbars, menus, form manipulation, etc. but you should still be able to use the site regardless of it.

    for those that browsers which have no JS support (either through design or choice), the users of them should still be able to retrieve and read the documents they request. coding a site which solely requires JS to do this might seem clever and look pretty, but it's actually quite crap.

    anyway, the really clever amongst us understand that you can do both. and it doesn't involve using <noscript> tags. but rather requires a proper understanding of DHTML and how to make it work for your users rather than against them.
    Copy linkTweet thisAlerts:
    @CharlesOct 07.2004 — [i]Originally posted by agent_x91 [/i]

    [B]well it's never caused any problems for me or any of my pages' viewers so it can't really be called "wrong" [/B][/QUOTE]
    Perhaps your page is chasing away JavaScript free folks so that they don't get counted as your visitors.

    You and I don't get to write the rules of web. That's the job of the World Wide Web Consortium ([url=http://www.w3.org/]W3C[/url]). And in the spring of 1998 the W3C made it wrong to omit the "type" attribute with the SCRIPT element. A few years back an organization called Browser Watch kept a list of browsers that numbered over 300. And that 300 didn't count different versions of each browser and the list didn't include Braille or audio browsers. When you have tested your HTML improvement on every browser that exists we can discuss which is better, your empirical or my standards compliant method of web design.

    Another of the W3C's simple rules is that we should ensure that our pages are still usable when scripting is turned off or not supported. The problem is with those pesky Braille and audio browsers again. And some people with non-visual disabilities have other reasons why they cannot browse with JavaScript. This is not to say that one ought not to eschew JavaScript. Rather, one ought to be careful not to make a JavaScript [i]dependent[/i] page.
    Copy linkTweet thisAlerts:
    @Frank1984authorOct 07.2004 — Is there a language that every browser can read (except for HTML)?
    Copy linkTweet thisAlerts:
    @CharlesOct 07.2004 — No, I'm afraid not. But this doesn't mean that you ought to eschew client side scripting. Just be careful how you use it. Start with a page that works with just HTML, add CSS for layout and presentation and then use scripting for your bells and whistles.

    Server side scripting always works if it works at all and often that's the better way to go.
    Copy linkTweet thisAlerts:
    @jbotOct 07.2004 — [i]Originally posted by Frank1984 [/i]

    [B]Is there a language that every browser can read (except for HTML)? [/B][/QUOTE]


    yeah, plain text. ?
    Copy linkTweet thisAlerts:
    @David_HarrisonOct 07.2004 — [i]Originally posted by agent_x91 [/i]

    [B]go almost anywhere on the web and you see javascript. almost every browser supports javascript. if you are unable to use javascript, you're severely limited and the most you can do for someone is point them to a browser which supports javascript inside the <noscript> tags of your page. [/B][/QUOTE]
    Not so, you should respect that some users don't want or can't enable JavaScript and take that into consideration. I've uploaded a script that does just that, take a look.

    It was created originally for Turak in [url=http://www.webdeveloper.com/forum/showthread.php?s=&threadid=36176&highlight=image+viewer]this[/url] thread.

    [upl-file uuid=eb4dbd8c-9ffe-48b6-9a9e-e5189a1a7b90 size=13kB]pop-up_image_viewer.zip[/upl-file]
    Copy linkTweet thisAlerts:
    @llanitedaveOct 07.2004 — "...if you are unable to use javascript, you're severely limited..."

    I partly agree, but only partly. I'd use the slant that if you ARE able to use JavaScript, you can tremendously enhance the user experience. However, there are relatively few types of information transmittal that really *need* it. I happen to be writing a JavaScript application right now that is one of the few exceptions -- in this case Javascript makes the content somewhat more accessable than a downloaded applet might. That's a special-purpose use, though. If your goal is to exchange information -- professionally, socially, politically, or personally -- the information should take precedence. Javascript can enhance the format or the presentation, but the information itself should not be dependent on it.

    Admittedly, though, there are times when there's no substitute for a scripting language -- like when the presentation IS the information!
    Copy linkTweet thisAlerts:
    @agent_x91Oct 07.2004 — Sure you don't [B]need[/B] javascript to deliver content, but you certainly need a scripting language of some type to use any sort of special effects. HTML alone is quite simply boring.

    maybe im not making myself clear enough. i am not saying that javascript is necessary, i am merely saying that without it, you are limited to basic html formatting, which while is the main building blocks of any website, isn't really very interesting
    Copy linkTweet thisAlerts:
    @David_HarrisonOct 07.2004 — [i]Originally posted by agent_x91 [/i]

    [B]Sure you don't [B]need[/B] javascript to deliver content, but you certainly need a scripting language of some type to use any sort of special effects. HTML alone is quite simply boring.



    maybe im not making myself clear enough. i am not saying that javascript is necessary, i am merely saying that without it, you are limited to basic html formatting, which while is the main building blocks of any website, isn't really very interesting [/B]
    [/QUOTE]
    Yes, HTML may be dull and boring, however that's the whole reason that JavaScript exists. JavaScript can be used to add "fluff" to a page, but that's all it should be, fluff. The content that is delivered should not DEPEND on JavaScript.

    Maybe I'm not making myself clear enough, an accessible web-site doesn't have to be dull and it can use JavaScript, but only if it's used in the correct way. Check out [url=http://www.1976design.com/blog/]Dunstan's blog[/url] for example.
    Copy linkTweet thisAlerts:
    @llanitedaveOct 09.2004 — maybe im not making myself clear enough. i am not saying that javascript is necessary, i am merely saying that without it, you are limited to basic html formatting, which while is the main building blocks of any website, isn't really very interesting
    [/QUOTE]


    Well, if the [B]content[/B] is interesting and compelling, then the presentation should be essentially invisible. 90% of the time, scripting is superfluous. 10% of the time, it's a really good idea.

    If the site is based on and dependent on user interaction, then scripting is probably right. If it's primarily to pass along information -- presenting text and images, then you probably don't need it.
    Copy linkTweet thisAlerts:
    @David_HarrisonOct 09.2004 — [i]Originally posted by llanitedave [/i]

    [B]If the site is based on and dependent on user interaction, then scripting is probably right.[/B][/QUOTE]
    If a site is dependent on user interaction then it should employ server-side techniques. There's nothing wrong with using JavaScript to allow user-interaction though, so long as if JavaScript is not supported then users can still access all the content on the site.
    Copy linkTweet thisAlerts:
    @jbotOct 09.2004 — [i]Originally posted by lavalamp [/i]

    [B]There's nothing wrong with using JavaScript to allow user-interaction though, so long as if JavaScript is not supported then users can still access all the content on the site. [/B][/QUOTE]


    using JS and SSI, a site developer can easily cope for all users, disabled or otherwise. ?
    Copy linkTweet thisAlerts:
    @agent_x91Oct 09.2004 — erm why are we all arguing over how useful javascript is in a post entitled "Is this code OK?"

    We've all drifted a lil far from the topic...
    Copy linkTweet thisAlerts:
    @David_HarrisonOct 09.2004 — [i]Originally posted by jbot [/i]

    [B]using JS and SSI, a site developer can easily cope for all users, disabled or otherwise. ?[/B][/QUOTE]
    Write me a blog script using (X)HTML, CSS, JavaScript and SSI's.

    [i]Originally posted by agent_x91 [/i]

    [B]We've all drifted a lil far from the topic... [/B][/QUOTE]
    As long as what is being discussed is still useful I don't see a problem with it. Saves creating a new thread.
    Copy linkTweet thisAlerts:
    @agent_x91Oct 09.2004 — yeah lol, but it's not useful. we all have our own uses for javascript, and it's more useful to some people than others. let's just leave it at that.
    Copy linkTweet thisAlerts:
    @David_HarrisonOct 09.2004 — Some webdevelopers's uses for JavaScript are ... incorrect. I'd rather that these webdevelopers didn't continue to use JavaScript in such a way as to exclude some users when these users needn't be excluded.
    Copy linkTweet thisAlerts:
    @agent_x91Oct 09.2004 — There is no incorrect use for javascript - if it does the job, and it does it well, it is fine.
    Copy linkTweet thisAlerts:
    @CharlesOct 09.2004 — [i]Originally posted by agent_x91 [/i]

    [B]yeah lol, but it's not useful. we all have our own uses for javascript, and it's more useful to some people than others. let's just leave it at that. [/B][/QUOTE]
    The problem is that some applications of JavaScript cause harm. If we build public space on the internet but exclude those with disabilities then we hurt those people.
    Copy linkTweet thisAlerts:
    @David_HarrisonOct 09.2004 — [i]Originally posted by agent_x91 [/i]

    [B]There is no incorrect use for javascript - if it does the job, and it does it well, it is fine. [/B][/QUOTE]
    It only does the job if it is enabled. If it is not enabled on a users machine and a site depends on the use of JavaScript to function (eg. for navigation), then that user is left high and dry.
    Copy linkTweet thisAlerts:
    @agent_x91Oct 09.2004 — if navigation is dependent upon javascript, then that's where the useful <noscript> tag comes into play. Simply create a HTML-only version of the website inside these tags - easy.
    Copy linkTweet thisAlerts:
    @David_HarrisonOct 09.2004 — And how many people bother with <noscript> tags?

    But what is the point of using <noscript> tags when it is perfectly possible to create a navigation system that is accessibe to BOTH JavaScript enabled and disabled users? Simply lay down the navigation markup, then use the JavaScript DOM to add in all the fancy effects your heart desires. This second method makes it easier to alter the menu in future because then all that needs to be done is one change and not two.
    Copy linkTweet thisAlerts:
    @llanitedaveOct 10.2004 — [i]Originally posted by lavalamp [/i]

    [B]If a site is dependent on user interaction then it should employ server-side techniques. There's nothing wrong with using JavaScript to allow user-interaction though, so long as if JavaScript is not supported then users can still access all the content on the site. [/B][/QUOTE]


    I thought I was going to agree with this, but for the sake of argument I think I'll argue. Server-Side scripting is best used for shared persistent changeable data. Not all user interaction involves that.

    Imagine an ebook, an adventure story, perhaps, distributed over the web, but downloadable to a client's machine. The client could save the book's contents locally, making server access irrelevent. The ebook would contain all the "basic" content in html format -- the story itself and any illustrations. But there's more to it than that. Suppose there is enhanced content beyond what html can provide. Maybe the readers will want to see a view of the sky at some point in the story, to look at the relative location of the sun or stars. Suppose one wanted to view a map of the adventure's region, that has icons depicting the locations of the protagonists at various points along the way. Suppose that a language translation tool was involved, but since the entire set of data resides on the client machine, the data would be read from a .js file. A server-side script would not be available for this, but packaging the proper tools in javascript would be extremely helpful. If the user doesn't have javascript support, she can still read the text and see the illustrations. But to get the FULL content, to provide the full practical access to all the potential of a site, then Javascript is sometimes (a minority of times, but still sometimes) an absolute necessity.

    This is only one example, and maybe not the best one. I'm sure there are others.
    ×

    Success!

    Help @Frank1984 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,
    )...