URL Encoding removal

112 views
Skip to first unread message

Morris Gray

unread,
Aug 7, 2012, 8:25:51 AM8/7/12
to tiddl...@googlegroups.com
I have a script I use that has changed it's behavior in 2.6.5 compared to 2.5 the script is
<script>var today=new Date();document.write('<font style="color:#666">'+'URL='+window.location+'</font>')</script>

The result now has URL encoding  in it for the spaces
URL=file:///V:/TiddlyWiki/TW%20Empty%202.6.5/TW%20Empty%202.6.5.html

How can I remove the encoding?

Thanks in advance

Eric Shulman

unread,
Aug 7, 2012, 1:24:19 PM8/7/12
to TiddlyWiki
It's not clear to me why there is any difference between your document
built with 265 vs 250. The "window.location" variable is defined by
the browser, not the TWCore, so there should be no change in value due
to different TWCore versions. Also, I assume you are using the same
version of InlineJavascriptPlugin in both documents, so that wouldn't
be a source of the difference either.

Regardless of the cause, you can easily work-around the difference by
using
decodeURIComponent(window.location)
to convert "%20" back in to a true space character. This also
converts any other special character encoding that may be present in
the window.location value.

Thus, your script would be:

<script>var today=new Date();document.write('<font
style="color:#666">'+'URL='+decodeURIComponent(window.location)+'</
font>')</script>

Also, a few script code notes:

1) You don't seem to be using the "today" variable that you are
setting. Why is that code there at all?
2) Rather than using document.write(...) to generate the output using
HTML syntax, you could use TW syntax, and simply "return" the
resulting string for automatic rendering (a built-in feature of
InlineJavascriptPlugin handling for embedded scripts)

<script>
return '@@color:#666; URL="""'+decodeURIComponent(window.location)
+'"""@@'
</script>

* use '@@attr:value;...@@' to set the font color
* use """...""" surrounding the decoded window.location to prevent TW
from creating an external link (i.e., just render URL as text)

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...
http://www.TiddlyTools.com/#Donations

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:
http://www.TiddlyTools.com/#Contact

PMario

unread,
Aug 7, 2012, 2:05:53 PM8/7/12
to TiddlyWiki
Hi,
I did notice, that FireFox changed there behaviour for
window.location. I think it started with version 13 and changed again
with version 14.
-m

Morris Gray

unread,
Aug 7, 2012, 8:16:58 PM8/7/12
to tiddl...@googlegroups.com
To clarify: The browser is FF 14.0.1 Both TiddlyWikis are identical except for the versions i.e. 2.5 vs 2.6.5.

It appears it must be a combination of the version of FF and TW is causing the encoding problem.  Whether it is worth exploring further I don't know.


1) You don't seem to be using the "today" variable that you are
setting.  Why is that code there at all?

It is a legacy of when the script was bigger and my being a cut and paste script writer:-)

Thanks very much Eric, your answers are always more than an answer but a lesson as well.  You deserve a beer for this one so I sent a you a 'Tip' to by one or two depending on the exchange rate:-).

enjoy,
M.


Reply all
Reply to author
Forward
0 new messages