Javascript code renders as links when javascript turned off in browser

I’m learning javascript. The portion I’m learning right now is how to write a short page that alerts the user that their javascript is not enabled. Then , when they enable it, javascript code written into this same page auto-redirects the user to a another page that requires javascript.

I run firefox with the noscript add on. I’m learning to write code that first asks the user to enable javascript. When they do, redirect to mypage.html

The code below renders “Please enable javascript” when javascript is turned off - as it should. The autoredirect happens when javascript is turned on - as it should.

The problem is the absolute url of the “mypage.html” file in the code is also rendered as a blue link when javascript is off. I don’t want that rendering when off.

I do use html comment tags as you can see in the code below. They don’t stop the rendering of the link. Can anyone help?

Here is the code:

<!DOCTYPE html>
<style type=“text/css”>
body {margin: 20em;}
<title>No Javascript Page</title>

<noscript>Please enable javascript</noscript>

<script type=“text/javascript”>

I am confused, what link are you referring to in the above source as the only code you have changes the URL in the browser not on the page itself. Also in your markup you have a tag called xhtml, a tag called html exists but no tag by that name exists in the HTML spec and never will.

I took the “x” out of <xhtml>. Thanks for the feedback.

I did not write a link. I wrote this method: location.replace(“mypage.html”);

I wrote it to redirect the user when javascript is turned on. It does redirect when js is on.

Firefox renders it as a link when javascript is turned off:


I’m trying to figure out how to stop Firefox from rendering it as a link while the usr is trying to enable javascript in his browser.

I’m with Sgt Legend :confused:

I copied and pasted your code (minus the x in xhtml) and with javascript turned off in my FF8 all I get in the browser is the message “Please enable javascript”.

There is no link at all displayed on the page.


Not necessarily my business to comment here, but a better approach to web design and use of JS is to make a page with accessible content and then use JS as an enhancement to the page. I guess it depends on what you are trying to do, but it’s a good principle to work by.[/ot]

just did a quick :google:

maybe it’s your noscript add-on that is displaying the url as a link.

Thanks for your help.


I tried again and my firefox still shows the link. I have to find out why my browser is doing this.

I read the comment about trying not to use javascript. My website will have two parts. The https/javascript registration part and the http/html text part. I’m working on and talking about the secure part right now. I’ll need javascript for ajax in the secure part.

I say this for 2 reasons, I want to use ajax to validate form data, using onfocus and onblur events, before submit, and the page we are talking about right now is an https page. I wonder if that is causing firefox to show the links.

This is a brain twister. Thanks to everyone for the comments.

Off Topic:

:bouncy3: DANGER Will Robinson, DANGER :bouncy3:

You mention you are learning javascript and so you might not be aware. AJAX is just a specific way of using javascript to communicate with the server. It’s not a separate language or technology, and being nothing more than javascript it (along with any ajax code) can be easily bypassed by a malicious user.

Bottom line: any user inputted data must be validated in your server side script when it receives the data (which, by the way, might not be sent from your form at all by a malicious user) and client side validation (with javascript and/or ajax) is just an optional extra to enhance user experience.

Yes, I use noscript. The link disappears when I tell noscript to stop blocking javascript. I was assuming the links appear when javascript is turned off for any reason. Maybe noscript is specifically designed to show them when it is blocking js .I am assuming many others will use this add on as well, that’s why I’m trying to learn how to deal with it (prevent these links from showing to those who use noscript).

“DANGER Will Robinson DANGER”

Thanks. I can use the laugh.

I use php to validate, and communicate with mysql. A php file for each separate form element contains a regex specifically for that form element. This regex checks (not submits) the data for that element only by using XMLHttpRequest object . When all user input passes the series of regexes (nothing submitted yet, just checked by a regex), the user submits to a separate server side php validation script.

There will be so much going on for each user that I want to keep all activity on one dynamic page for ease of use. No one gets lost - including me.

sounds good :tup:, that’s the way it should be.

Thanks for your help, and…

The ajax per element, <?php if(regex) {echo “Thanks”}; ?>, validation requires javascript. I have to make sure the user has it on before I show them the registration form. I have to test the users browser for js on a non registration page, and auto-redirect to the actual registration page only when js is on.

I learned from the responses here that the noscript add on is rendering those links. Other users will have this add on, so I have to learn more about it to see if I can test for it and response as necessary. I don’t want my customers to see the links at all, even before they turn js on. That’s why I’m looking for a way to turn off the links to the scripts.

The links are a dead end, but they show the path to the scripts, and they look bad.

Thank for your help!!

I’m not sure why you want users to turn on their js just for the client side validation (with or without ajax).

If the user has js turned off, all that should mean is that there will be no client side validation and their inputted data will be validated in your separate server side script anyway when they click the submit button.

If you insist users turn on their js, at least the less tech-savvy ones might suspect you are trying to do something “nasty” on their pc and so you risk losing them.

There is no reason at all saying a registration process must use javascript to function securely.

Just some food for thought :slight_smile:

Thanks for your question, and your ideas.

I want to move beyond a form that shows errors only by scrolling the form after the submit button is clicked. I want the user to know within half a second or less of moving away from each form element if their input into that element has errors, - that is, if they entered 876r4 as a zip code, etc

The faster I can show the user any errors they make, the faster they can get through the form. Scrolling and searching slows things down.

That’s all fine and good. As long as you are aware you need javascript for “instant” validation and if you try to impose the use of javascript on your js disabled users, albeit a very small number most likely, you risk losing them and their registration. That’s the only point I was trying to make.

Also, why use AJAX (which slows down your validation speed) unless you are querying a database as part of your validation?

Yes, what you’re saying is true. Not everyone loves javascript. I’ve been talking about the secure part of the site on this thread, which is the part people will go to after spending time on the html, css only, section. If they spend a lot of time on the non secure part, I think that means they are interested and not so concerned about the use of javascript on the secure part.

I will try not to use any javascript on the non secure part, for the reasons you’re talking about.

Javascript is not going to be the first thing they find on the entire site. I won’t be like the speed bump on the lazy sunday afternoon drive.

No one will be able to go to the secure site directly by typing the url into their browser. They will have to link from the non secure site.

Also, the things they will be able to do after registering will require ajax as well. That provides the quick functionality. There will be a database involved. If it slows down, I’ll upgrade the hardware.

I’m still learning to code. There will always be a learning curve to coding. It won’t always be as steep as it is now, but it will always be there to some degree. I don’t have all the answers. I have to make some decisions about how to do things, and see how it goes. No one method has all the advantages and no disadvantages.

Thanks for your feedback. Thanks for helping.