Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 921033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:48:39+00:00 2026-05-15T18:48:39+00:00

Is there any authoritative reference about the syntax and encoding of an URL for

  • 0

Is there any authoritative reference about the syntax and encoding of an URL for the pseudo-protocol javascript:? (I know it’s not very well considered, but anyway it’s useful for bookmarklets).

First, we know that standard URLs follow the syntax:

scheme://username:password@domain:port/path?query_string#anchor

but this format doesn’t seem to apply here. Indeed, it seems, it would be more correct to speak of URI instead of URL : here is listed the “unofficial” format javascript:{body}.

Now, then, which are the valid characters for such a URI, (what are the escape/unescape rules) when embedding in a HTML?

Specifically, if I have the code of a javascript function and I want to embed it in a javascript: URI, which are the escape rules to apply?

Of course one could escape every non alfanumeric character, but that would be overkill and make the code unreadable. I want to escape only the necessary characters.

Further, it’s clear that it would be bad to use some urlencode/urldecode routine pair (those are for query string values), we don’t want to decode ‘+’ to spaces, for example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:48:40+00:00Added an answer on May 15, 2026 at 6:48 pm

    My findings, so far:

    First, there are the rules for writing a valid HTML attribute value: but here the standard only requires (if the attribute value if enclosed in quotes) an arbitrary CDATA (actually a %URI, but HTML itself does not impose additional validation at its level: any CDATA will validate).

    Some examples:

     <a href="javascript:alert('Hi!')">     (1)
     <a href="javascript:if(a > b && 1 < 0) alert(  b ? 'hi' : 'bye')">   (2)
     <a href="javascript:if(a&gt;b &amp;&&amp; 1 &lt; 0) alert( b ? 'hi' : 'bye')">  (3)
    

    Example (1) is valid. But also example (2) is valid HTML 4.01 Strict. To make it valid XHTML we only need to escape the XML special characters < > & (example 3 is valid XHTML 1.0 Strict).

    Now, is example (2) a valid javascript: URI ? I’m not sure, but I’d say it’s not.

    From RFC 2396: an URI is subject to some addition restrictions and, in particular, the escape/unescape via %xx sequences. And some characters are always prohibited:
    among them spaces and {}# .

    The RFC also defines a subset of opaque URIs: those that do not have hierarchical components, and for which the separating charactes have no special meaning (for example, they dont have a ‘query string’, so the ? can be used as any non special character). I assume javascript: URIs should be considered among them.

    This would imply that the valid characters inside the ‘body’ of a javascript: URI are

     a-zA-Z0-9 
     _|. !~*'();?:@&=+$,/-   
     %hh : (escape sequence, with two hexadecimal digits)
    

    with the additional restriction that it can’t begin with /.
    This stills leaves out some “important” ASCII characters, for example

    {}#[]<>^\
    

    Also % (because it’s used for escape sequences), double quotes " and (most important) all blanks.

    In some respects, this seems quite permissive: it’s important to note that + is valid (and hence it should not be ‘unescaped’ when decoding, as a space).

    But in other respects, it seems too restrictive. Braces and brackets, specially: I understand that they are normally used unescaped and browsers have no problems.

    And what about spaces? As braces, they are disallowed by the RFC, but I see no problem in this kind of URI. However, I see that in most bookmarklets they are escaped as “%20”. Is there any (empirical or theorical) explanation for this?

    I still don’t know if there are some standard functions to make this escape/unescape (in mainstream languages) or some sample code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any native compression (for javascript/css files) available in ASP.NET?
Are there any good resources (books, authoritative guides, etc.) for design patterns or other
There any way to let an application know if there is any specific change
Is there any way to change the BackColor of the border of a panel
Are there any open-source compression/decomp libraries available for Ruby? Has anyone implemented LZW? Or,
Is there any way I can run class files (i.e. with main as the
Is there any way to view the reduction steps in haskell, i.e trace the
Is there any advantage of using int vs varbinary for storing bit masks in
Is there any real difference to screen reader users (or any users really) whether
Is there any way to change the icon of an application after it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.