Forum Moderators: open

Message Too Old, No Replies

<noscript> tag

         

Psycho1

10:13 am on Mar 1, 2003 (gmt 0)

10+ Year Member



I'm using a simple javascript jump box for parts of the navigation of my site, but I just learned that Google doesn't follow these links. I did some research on <noscript> but I can never get it 100% correct. I'm using this code right now for the jump box:

<FORM>
<SELECT>
<OPTION VALUE="pics/page1.html">Page 1
<OPTION VALUE="pics/page2.html">Page 2
<OPTION VALUE="pics/page3.html">Page 3
</SELECT>
<INPUT TYPE="button" VALUE="Go" onClick="jumpBox(this.form.elements[0])">
</FORM>

Now...how would I correctly use <noscript> so a list of text links appear if the browser doesn't support javascript? I tried just putting the <noscript> after the form end tag, but the jump box still displays on Mozilla even when I turn javascript off....the jump box won't work though of course. I experimented with enclosing the form in a <script> tag, but that won't work either. Any help appreciated.

Psycho1

10:16 am on Mar 1, 2003 (gmt 0)

10+ Year Member



I just noticed there is a message about noscript on this forum already, but they only discussed why it's used...they didn't get into actual examples so I hope this post is okay.

DrDoc

4:06 pm on Mar 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World! :)

Well, <noscript> is used to display alternative content in browsers that either don't support JavaScript or have it turned off.

For example:

<script type="text/javascript">
document.write("Hello World");
</script>
<noscript>
Hello Earth
</noscript>

A browser that supports JavaScript will display "Hello World", whereas a non-JavaScript-capable browser will display "Hello Earth" instead.

For more information on HTML tags you can visit the W3C HTML4 Elements [w3.org] page.
For specific information on the <noscript> tag, visit the Scripts in HTML [w3.org] page

tedster

5:21 pm on Mar 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For a <noscript> tag to be valid, it should follow a <script> tag. But your dropdown menu is a form that fires on an event handler -- and strictly speaking, that doesn't use the <script> tag.

You might consider using a document.write() something like this:

<script>
document.write("entire form tag")
</script>
<noscript>
list of text links
</noscript>

Psycho1

9:30 pm on Mar 1, 2003 (gmt 0)

10+ Year Member



Thanks for the help. None of the websites I visited gave an example of using <noscript> with a simple form, which threw me off.

Psycho1

12:23 am on Mar 2, 2003 (gmt 0)

10+ Year Member



I was just testing this some more and I realized it's only working correctly when javascript is off. When I have javascript enabled, nothing is displayed. Here's what I did:

<script>
document.write("<FORM>
<SELECT>
<OPTION VALUE="pics/page1.html">Page 1
<OPTION VALUE="pics/page2.html">Page 2
<OPTION VALUE="pics/page3.html">Page 3
</SELECT>
<INPUT TYPE="button" VALUE="Go" onClick="jumpBox(this.form.elements[0])">
</FORM>")
</script>
<noscript>
Why doesn't this work?
</noscript>

Like I said, works perfectly when javascript is disabled...but nothing is displayed if javascript is enabled.

DrDoc

4:06 am on Mar 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is that there can't be any line-breaks in a document.write statement. There are two workarounds:

1) put everything in one document.write, and use \n wherever you want a line break

2) use a separate document.write for each line

So, something like this would work:

<script type="text/javascript">
document.write("<FORM>\n<SELECT>\n<OPTION VALUE=\"pics/page1.html\">Page 1\n<OPTION VALUE=\"pics/page2.html\">Page 2\n<OPTION VALUE=\"pics/page3.html\">Page 3\n</SELECT>\n<INPUT TYPE=\"button\" VALUE=\"Go\" onClick=\"jumpBox(this.form.elements[0])\">\n</FORM>");
</script>

Note that quotes are escaped like this: \"

The text should be on the same line.

Psycho1

5:23 am on Mar 2, 2003 (gmt 0)

10+ Year Member



Thanks DrDoc, works perfectly now:)

Psycho1

7:37 am on Mar 4, 2003 (gmt 0)

10+ Year Member



One more question:)

Has anyone verified that Google doesn't mind the \ before and after the link..example:
<OPTION VALUE=\"pics/page3.html\">

The main reason I'm doing this is so Google visits these links, and I want to make sure Google can pick up the links correctly.

keyplyr

5:52 pm on Mar 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Alternative: You could create a site map, hard coding links to all pages on you website and link to it from your default page. This works terrific for bots and would be just one layer from the top.