...

View Full Version : Hide from old browsers



mw2005
08-24-2005, 09:38 AM
Hi;
If i have an external JS file do i need to hide it from old browsers and if so where do i put the <!-- and //-->

Any help will be appreciated,
Thanks,
MW2005

jbot
08-24-2005, 09:51 AM
no, don't need to hide it. non-JS browsers will just ignore the tags and anything between them as long as you include the appropriate comments, eg for HTML 4:


<script type="text/javascript">
<!-- //


// -->
</script>

Bill Posters
08-24-2005, 09:52 AM
What is in there that older browsers shouldn't see?
How old are the 'old browsers' you're referring to?
Are they sufficiently popular for you to consider them?

Fwiw…

<script type="text/javascript">
<!--


//-->
</script>

mw2005
08-24-2005, 09:54 AM
Thanks for that,
Do i need to do that for external JS files like:

<script type = "text/javascript" src = "whatever.js">
<!--

//-->
</script>

Bill Posters
08-24-2005, 10:03 AM
If you were set on using comments, then simply enclose all the js code within the external js file within sgml comments.

e.g.

site.js


<!--

function one() {
…
}

function two() {
…
}

function three() {
…
}

-->

mw2005
08-24-2005, 10:10 AM
Thanks for all of your help :thumbsup:

glenngv
08-24-2005, 11:04 AM
If you were set on using comments, then simply enclose all the js code within the external js file within sgml comments.

e.g.

site.js


<!--

function one() {
…
}

function two() {
…
}

function three() {
…
}

-->

That won't work. You don't need to put HTML comments inside a .js file.
Javascript parser is different from HTML parser.

When you include the .js file in an HTML file, you don't need to put HTML comment as there's nothing inside the script tag to hide.


<script type="text/javascript" src="file.js"></script>

Bill Posters
08-24-2005, 12:15 PM
I got a bum steer, guv'nor.
I never use SGML comments around embedded js, so it's not something I have experience of, but I was already quite certain that they weren't necessary.
I did a quick Google around for verification and the one page I could find that mentioned sgml comments and external js files mentioned it was permissable.

That'll learn me not to trust my own knowledge. ;)

jbot
08-24-2005, 02:37 PM
I did a quick Google around for verification and the one page I could find that mentioned sgml comments and external js files mentioned it was permissable.

yeah, because everything on the Net is correct, right enough.

Bill Posters
08-24-2005, 02:49 PM
yeah, because everything on the Net is correct, right enough.
The site I alighted upon seemed as credible as this forum which, sorry to break it to you, is also on the net.

But thanks for reminding me not to believe everything you say. ;)

jbot
08-24-2005, 02:54 PM
But thanks for reminding me not to believe everything you say.

glad to be of service, bill.

oh look, a flying pig ... :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum