I was trying to generate an HTML snippet using AJAX. From the pile of troubleshooting documents I read, I came across this trick that by adding "noscript=true" to the href attribute, the generated code will be cleaner. However, it did not say where and how nor why to use that.

Can anyone explain or elaborate on this topic? Thanks a bunch!!

4 answers

0
points
This was chosen as the best answer

Using a server-side script

The book is assuming your the server-side script will be aware of the query string and take appropriate action. In php it would look something like:

if($_GET["noscript"]=="true") {

//clean generated code

}

Answered about 7 years ago by Gerlando
o.k.w 2355
0
points

May I know where did you read that from and do you know which Ajax framework/utility are you using? "noscript=true" is not a common/standard query string (if indeed it is to be added to the end of the href attribute as ?noscript=true).

It's more likely to be proprietary to whatever you are reading/using. You'll need to provide more info for a suitable answer.

Answered about 7 years ago by o.k.w
0
points

From the book Beginning Javascript and CSS Development with jQuery

I am quoting that paragraph:

Using a server-side script, you could also add logic at the server side that presents this contents within your normal template depending on whether scripting is enabled on the client side. To do that, what you would do is, by default, make the link tabs.html?noscript=true Then in your javascript, automatically remove the query string portion ?noscript=true at page load, which would then signal your server-side script to serve only the content, rather than the content within your template.

Essentially, does that mean that with noscript=true on, the HTML page will serve only whatever is between noscript tag, and no source code will be seen?

Answered about 7 years ago by Steve Hsieh
danwellman 5600
0
points

I'm pretty sure this will not happen automatically. You would need a server-side script that looks for the ?noscript=true query string and does something when it encountered it (i.e. serve a basic page that doesn't require scripts to work)

There are probably stock scripts out there that you could use, but I don't think it's automatic.

jQuery certainly doesn't have this feature 'built-in'

.NET may have some default behviour when this is used but I doubt it

Not sure what you mean about source-code? Source-code (i.e. the underlying HTML) will always be visible to the end-user - all they have to do is choose view source in their browser and the code will be shown. There is no way to stop this or hide the code...

Answered about 7 years ago by danwellman
  • Great, thanks. I just needed to know if this was an undocumented trick or something. I thought that was one way to hide the Javascript source code from the user as well. Then again, if the user couldn't see javascript, neither could the browser, and the page just won't work. Thanks for clarifying that. Steve Hsieh about 7 years ago