SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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>
    <xhtml>
    <head>
    <style type="text/css">
    body {margin: 20em;}
    </style>
    <title>No Javascript Page</title>
    </head>

    <body>
    <noscript>Please enable javascript</noscript>

    <script type="text/javascript">
    <!--
    location.replace("mypage.html");
    //-->
    </script>
    </body>
    </xhtml>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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.

  3. #3
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:


    location.replace("mypage.html");


    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.

  4. #4
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm with Sgt Legend

    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.

  5. #5
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,118
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Off Topic:

    Quote Originally Posted by settingsun View Post
    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.
    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.

  6. #6
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just did a quick

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

  7. #7
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help.

    hmm...

    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.

  8. #8
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Quote Originally Posted by settingsun View Post

    .....I want to use ajax to validate form data, using onfocus and onblur events, before submit, .......
    DANGER Will Robinson, DANGER

    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.


  9. #9
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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).

  10. #10
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "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.

  11. #11
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by settingsun View Post
    .......the user submits to a separate server side php validation script.....
    sounds good , that's the way it should be.

  12. #12
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!!

  13. #13
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  14. #14
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  15. #15
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by settingsun View Post
    ....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'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?

  16. #16
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •