Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #11590

Re: ASPX, VBScript, JavaScript, Double-Underscored Variables and setTimeOut

Newsgroups microsoft.public.scripting.vbscript
Date 2017-04-02 05:06 -0700
References <1155100979.316328.119910@m73g2000cwd.googlegroups.com>
Message-ID <d9174c49-183b-4036-aadf-26171caba6bc@googlegroups.com> (permalink)
Subject Re: ASPX, VBScript, JavaScript, Double-Underscored Variables and setTimeOut
From flap13@gmail.com

Show all headers | View raw


среда, 9 августа 2006 г., 8:22:59 UTC+3 пользователь Shadow Lynx написал:
> That subject packs a whallop, so let me explain in better detail what's
> happening and how it relates to ASPX pages...
> 
> In a [large] nutshell, if the first <script /> on a page is of type
> "text/vbscript", you cannot use inline JavaScript statements that call
> setTimeout with functions that start with a double-underscore.  This is
> very relavant to ASPX (ASP Dot Net) pages because it means that
> AutoPostBacks will fail since they generally call the famous JavaScript
> statement "__doPostBack(...)" via a setTimeout call.
> 
> If you include a VBScript code block before any other code block on an
> ASPX page, the following statement will fail in IE (and the error is
> far from obvious since it is untrappable and says only that there is an
> Invalid character on line 1, character 2):
> 
> "javascript:setTimeout('__doPostBack(\'anyASPXcontrol\',\'\')', 0)"
> 
> This is a bug in IE 6 and possibly earlier versions (I only have v6 to
> play with.)  I do not know if it affects IE 7 as I have not installed
> that for testing lately.  Note that even though the prefix of
> "javascript:" is used, the setTimeout function assumes it's calling a
> VBScript function, presumably because the first script block is a
> VBScript block.
> 
> Here is a very simple page that shows this bug:
> http://www.digitolle.net/news/testscriptbug.htm
> 
> and here is the source code:
> 
> --------
> 
> <html>
> <head>
> <title>Test Script Bug</title>
> <!-- script type="text/javascript">
>     // If JavaScript is the first script, setTimeout works properly
>     // Unrem this script and both buttons will work.
> </script -->
> <script type="text/vbscript">
>     ' Just because this VBScript block exists,
>     ' setTimeout uses VBScript naming conventions.
>     ' Therefore, double underscore functions will fail
>     ' Rem this block out, and both buttons will work
>     ' Note that calling the function directly always works.
> </script>
> </head>
> <body>
>     <script type="text/javascript">
>         function __x() {
>             alert("test");
>         }
>     </script>
>     <input type="button" value="This will Work"
>         onclick="javascript:__x();" />
>     <br />
>     <input type="button" value="This will Fail"
>         onclick="javascript:setTimeout('__x()', 0);" />
> </body>
> </html>
> 
> --------
> 
> The obvious workaround is to always include a JavaScript block before
> any VBScript blocks, even if it's just an empty block.  If anyone else
> comes up with the same results on this test, please let me know.  Of
> course if this is a known issue and I'm beating a dead horse, again,
> please let me know because it's an odd issue to look up and it's
> definitely a brain stumper if you don't know it exists.

WOW! Awesome. I spent a hours to solve this!!!!!

Back to microsoft.public.scripting.vbscript | Previous | Next | Find similar | Unroll thread


Thread

Re: ASPX, VBScript, JavaScript, Double-Underscored Variables and setTimeOut flap13@gmail.com - 2017-04-02 05:06 -0700

csiph-web