javascript: and about: Protocols Not Working

G

Gene Wirchenko

Dear JavaScripters:

The text that I am using refers to javascript: and about:
protocols. None of the examples will run on my system (IE 9 on
Windows 7).

For
javascript:Date()
I get nothing. For
about:cache
and
about:plugins
I get a message of "Navigation to the webpage was canceled / What you
can try: / - Retype the address."

I have looked for settings to enable these and have found
nothing. What am I missing, please?

Sincerely,

Gene Wirchenko
 
M

Martin Honnen

Gene said:
Dear JavaScripters:

The text that I am using refers to javascript: and about:
protocols. None of the examples will run on my system (IE 9 on
Windows 7).

For
javascript:Date()
I get nothing.

Well where/how do you use it exactly? When I type that line into IE 9's
address bar and hit enter it displays the current date (e.g. Thu Dec 1
11:51:52 UTC+0100 2011) in the browser window.
For
about:cache
and
about:plugins
I get a message of "Navigation to the webpage was canceled / What you
can try: / - Retype the address."

I have looked for settings to enable these and have found
nothing. What am I missing, please?

Well that about stuff is something Netscape and later Mozilla
implemented, I have never heard that Microsoft browsers supported that.
 
R

Richard Cornford

Well where/how do you use it exactly? When I type that line into
IE 9's address bar and hit enter it displays the current date
(e.g. Thu Dec 1 11:51:52 UTC+0100 2011) in the browser window.

IE 9 seems to have an odd characteristic where is you _paste_ a
javascript pseudo-protocol URL into the address bar then it does not
include the 'javascript:' bit from the beginning, and you have to re-
type it manually.
Well that about stuff is something Netscape and later Mozilla
implemented, I have never heard that Microsoft browsers supported
that.

Yes, Microsoft provide other means of accessing that sort of
information. The cache from:-

Tools->Internet Options...->General(tab)->Browsing history(section)-
Settings(button)->View Files(button).

- and the plug-ins from:-

Tools->Internet Options...->Programs(tab)->Manage add-ons(button).

Richard.
 
R

Richard Cornford

Well where/how do you use it exactly? When I type that line into
IE 9's address bar and hit enter it displays the current date
(e.g. Thu Dec 1 11:51:52 UTC+0100 2011) in the browser window.

IE 9 seems to have an odd characteristic where is you _paste_ a
javascript pseudo-protocol URL into the address bar then it does not
include the 'javascript:' bit from the beginning, and you have to re-
type it manually.
Well that about stuff is something Netscape and later Mozilla
implemented, I have never heard that Microsoft browsers supported
that.

Yes, Microsoft provide other means of accessing that sort of
information. The cache from:-

Tools->Internet Options...->General(tab)->Browsing history(section)-
Settings(button)->View Files(button).

- and the plug-ins from:-

Tools->Internet Options...->Programs(tab)->Manage add-ons(button).

Richard.
 
T

Tim Streater

Martin Honnen said:
Well where/how do you use it exactly? When I type that line into IE 9's
address bar and hit enter it displays the current date (e.g. Thu Dec 1
11:51:52 UTC+0100 2011) in the browser window.

I get nothing in Safari either. But I find this unsurprising, since
you've not told anyone to do anything with the date info that Date()
returns. If I go javascript:alert(Date()); then I get an alert panel up
with the date/time in it. Or I can do javascript:console.info(Date());
and get the time/date in the error console window as expected.

Or I can do javascript:document.write(Date()); and then it appears in
the browser window as expected. If IE9 is putting it there without
document.write I'd call that a bug.

Neither of these does anything in Safari.
 
M

Martin Honnen

Tim said:
I get nothing in Safari either. But I find this unsurprising, since
you've not told anyone to do anything with the date info that Date()
returns. If I go javascript:alert(Date()); then I get an alert panel up
with the date/time in it. Or I can do javascript:console.info(Date());
and get the time/date in the error console window as expected.

Or I can do javascript:document.write(Date()); and then it appears in
the browser window as expected. If IE9 is putting it there without
document.write I'd call that a bug.

Not at all, with a javascript: URL you are supposed to write some
Javascript code that is evaluated and whose value is then displayed in
the window or frame. At least that was the original intent when the
syntax was introduced. You even had to use
void 0
at the end of your Javascript code if you did not want the result of the
code to be displayed in the window or frame.
 
M

Martin Honnen

Martin said:
Not at all, with a javascript: URL you are supposed to write some
Javascript code that is evaluated and whose value is then displayed in
the window or frame.

http://home.arcor.de/martin.honnen/html/test2011120101.html is an
example, the iframe content is generated by a javascript: URL, works in
IE 9, Firefox, Google, Opera. The link works in IE 9, Firefox, Opera but
not in Chrome, but I don't get any error message so I am not sure
whether that is some kind of security restriction.
 
G

Gene Wirchenko

Well where/how do you use it exactly? When I type that line into IE 9's
address bar and hit enter it displays the current date (e.g. Thu Dec 1
11:51:52 UTC+0100 2011) in the browser window.

Exactly as you do. When I do that, I get nothing.
Well that about stuff is something Netscape and later Mozilla
implemented, I have never heard that Microsoft browsers supported that.

Why do I get a message "Navigation to the webpage was canceled"?
Cancelled? That implies that my entry was recognised but disallowed.
And so I went searching for a setting to allow it: a waste of time.

Why not "Unrecognised protocol"?

Sincerely,

Gene Wirchenko
 
E

Erwin Moller

Exactly as you do. When I do that, I get nothing.


Hi Gene,

Don't do that. ;-)
You can best compare the pseudoprotocol (javascript:X in an url, where X
is some javascript command) as follows:

<a href="javascript:X;">click me to execute javascript</a>
almost equals:
<script type="text/javascript">
X
</script>

Where X is your javascript.


So, if you do this (without any pseudoprotocol):
<script type="text/javascript">
Date();
</script>

what do you expect to happen?


Regards,
Erwin Moller
 
J

Jukka K. Korpela

http://home.arcor.de/martin.honnen/html/test2011120101.html is an
example, the iframe content is generated by a javascript: URL, works in
IE 9, Firefox, Google, Opera. The link works in IE 9, Firefox, Opera but
not in Chrome, but I don't get any error message so I am not sure
whether that is some kind of security restriction.

I would expect javascript: URLs to behave differently depending on
browser, in sufficiently complicated cases at least. There is no
specification on the exact meaning and treatment of such URLs.

By the way, your test code shows, on one of my browsers,
"Today is Fri Dec 02 2011 11:08:04 GMT+0200 (Suomen normaaliaika)."
What's that odd parenthetic note there? I know what it means... but why
does it appear in text in English? :)
Implicit Date to string conversions aren't really suitable even for
demos, as they may inadvertantly demonstrate the lack of proper
localization in JavaScript and its implementations.

But returning to javascript: URLs, yesterday I stumbled across a bug
(some key links not working at all on some modern browsers), which
turned out to be caused by legacy code that uses an href attribute with
javascript: URL _and_ target="_blank". Isolated to a simple case:
http://www.cs.tut.fi/~jkorpela/js/target.html
On Firefox 8, the "link" opens a new tab with about:blank contents. With
the target attribute removed,
http://www.cs.tut.fi/~jkorpela/js/targetless.html
it works as intended.
 
M

Martin Honnen

Jukka K. Korpela wrote:


But returning to javascript: URLs, yesterday I stumbled across a bug
(some key links not working at all on some modern browsers), which
turned out to be caused by legacy code that uses an href attribute with
javascript: URL _and_ target="_blank". Isolated to a simple case:
http://www.cs.tut.fi/~jkorpela/js/target.html
On Firefox 8, the "link" opens a new tab with about:blank contents. With
the target attribute removed,
http://www.cs.tut.fi/~jkorpela/js/targetless.html
it works as intended.


With the target being set, the browser first opens a new tab and in the
contents of that tab evaluates the Javascript code. As there is no
content at all in that tab the function call "openUp()" to a function
named "openUp" fails as no function is defined at all in the new tab. At
least that is how Mozilla and Opera do it, Chrome does what you want.
An attempt to "fix" that or at least to demonstrate the issue is
http://home.arcor.de/martin.honnen/html/test2011120201.html but it now
only gives a popup in Firefox and Chrome, Opera blocks it. And of course
with Firefox you now have a new empty tab and a popup window.

So none of that is really a viable approach.
 
J

Jukka K. Korpela

legacy code that uses an href attribute with
javascript: URL _and_ target="_blank".
[...]
With the target being set, the browser first opens a new tab and in the
contents of that tab evaluates the Javascript code. As there is no
content at all in that tab the function call "openUp()" to a function
named "openUp" fails as no function is defined at all in the new tab.

Sounds like a simple explanation, and Firefox indeed shows an error
message about openUp being undefined.
At least that is how Mozilla and Opera do it, Chrome does what you want.

Well, this wasn't really my code, or even my code. :) Just an
interesting observation. And although the fix would be simple, it seems
to be legacy code that nobody wants to take care of.
So none of that is really a viable approach.

Indeed, if someone wants to open a web page in a new window with
specific properties, it is surely much better to set up a normal link,
then add an onclick handler that creates a window for the link to use,
so that the page works fine when JavaScript is off and in a
cross-browser way when it is on. But I'm afraid there's a lot of code
around that uses javascript: URLs in href attributes instead of any
robust approach.
 
G

Gene Wirchenko

On Fri, 02 Dec 2011 10:01:30 +0100, Erwin Moller

[snip]
Don't do that. ;-)
You can best compare the pseudoprotocol (javascript:X in an url, where X
is some javascript command) as follows:

<a href="javascript:X;">click me to execute javascript</a>
almost equals:
<script type="text/javascript">
X
</script>

Where X is your javascript.
So, if you do this (without any pseudoprotocol):
<script type="text/javascript">
Date();
</script>

what do you expect to happen?

Mr. Moller, I have RTFM. javascript: is documented as replacing
the current document with the value generated by the code. Yes, this
is different from a <script> code block.

Just to be sure, I tried
javascript:document.write(Date());
and got the same results, namely nothing.

Sincerely,

Gene Wirchenko
 
T

Tim Streater

Gene Wirchenko said:
On Fri, 02 Dec 2011 10:01:30 +0100, Erwin Moller


Mr. Moller, I have RTFM. javascript: is documented as replacing
the current document with the value generated by the code.

Documented *where* ??
Yes, this is different from a <script> code block.

Just to be sure, I tried
javascript:document.write(Date());
and got the same results, namely nothing.

And where did you try this? In a browser's address bar, or within a
script, or what?
 
G

Gene Wirchenko

Documented *where* ??

In my text. I thought I found one on the Web, but I can not now.
At least one other person in-thread has stated it, too.
And where did you try this? In a browser's address bar, or within a
script, or what?

The address bar. Before posting, it did not even occur to me to
put it in a page.

Sincerely,

Gene Wirchenko
 
T

Tim Streater

Gene Wirchenko said:
In my text. I thought I found one on the Web, but I can not now.
At least one other person in-thread has stated it, too.


The address bar.

Hmmm. I've not seen its use there documented, but then, to be fair, I've
not looked as in my app, there is no address bar.
Before posting, it did not even occur to me to put it in a page.

I use it in a couple of places in hrefs.
 
D

Dr J R Stockton

In comp.lang.javascript message <1ohid7pebhai3ksa47bi7cpi91flu5olju@4ax.
In my text. I thought I found one on the Web, but I can not now.
At least one other person in-thread has stated it, too.

You should not believe everything that you read on the Web or in
newsgroups. I write with authority there; some of it I wrote myself.
 
A

Arno Welzel

Gene Wirchenko, 2011-12-01 03:28:
Dear JavaScripters:

The text that I am using refers to javascript: and about:
protocols. None of the examples will run on my system (IE 9 on
Windows 7).

For
javascript:Date()
I get nothing. For
about:cache
and
about:plugins
I get a message of "Navigation to the webpage was canceled / What you
can try: / - Retype the address."

I have looked for settings to enable these and have found
nothing. What am I missing, please?

"about:" is not a "protocol" and are no standard either. So don't expect
this to work universally in any browser.

Using "javascript:" is also a bad idea - better implement an event
handler for user interaction.
 
B

Bwig Zomberi

Gene said:
For
javascript:Date()

This does not have to work unless you use window.alert() or
document.write().

Some browsers support just "javascript:Date()" - they are being
user-friendly, that's all.

I get nothing. For
about:cache
and
about:plugins

These would work in Opera/Firefox. I don't think IE ever supported them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top