view-source:'+document.location'

  • Thread starter John Taylor-Johnston
  • Start date
J

John Taylor-Johnston

This will give me the source of the current page.

<a herf="javascript:document.location = 'view-source:'+document.location">testpage.htm</a>

I want to display the source of another page, using something like this but it doesn't work:

<a herf="javascript:document.location = 'view-source:'+'testpage.htm'>testpage.htm</a>

?? Won't work, unless it is saved on a server with http:// in front of it.
 
M

Martin Honnen

John said:
This will give me the source of the current page.

<a herf="javascript:document.location = 'view-source:'+document.location">testpage.htm</a>

I want to display the source of another page, using something like this but it doesn't work:

<a herf="javascript:document.location = 'view-source:'+'testpage.htm'>testpage.htm</a>

?? Won't work, unless it is saved on a server with http:// in front of it.

Try
<a href="testpage.htm"
onclick="location.href = 'view-source:' + this.href;
return false">
 
J

Janwillem Borleffs

John Taylor-Johnston said:
I want to display the source of another page, using something like this but it doesn't work:

<a herf="javascript:document.location =
'view-source:'+'testpage.htm'>testpage.htm said:
?? Won't work, unless it is saved on a server with http:// in front of it.

True, you will have to prepend a protocol. When you are not testing on a
webserver, you should use the file:// protocol.

Regarding the usage of the javascript: pseudo-protocol, you should read:
http://jibbering.com/faq/#FAQ4_24


JW
 
J

John Taylor-Johnston

MartinTry
<a href="testpage.htm"
onclick="location.href = 'view-source:' + this.href;
return false">

Thanks. Great. Just for fun, ii wanted to put in all inside the href=""

<a href="javascript:eek:nclick="location.href = 'view-source:' + this.href; return false"">click</a>

I have too many quotes. How can I work around this?

Still learning ...
 
L

Lasse Reichstein Nielsen

John Taylor-Johnston said:
Thanks. Great. Just for fun, ii wanted to put in all inside the href=""

<a href="javascript:eek:nclick="location.href = 'view-source:' + this.href; return false"">click</a>

That won't work. The script uses "this.href" which referst to the
actual href of the link. If you put the script itself into the href, then
it won't have the URL it needs.
I have too many quotes. How can I work around this?

To fix the quotes, use something like:

<a href="javascript:eek:nclick='location.href = \'view-source:\' + this.href;
return false'">click</a>

As I said, it won't work. You generally shouldn't use the javascript:
pseudo protocol. You definitly shouldn't return false from it, it isn't
an event handler.
Still learning ...

Unlearn "javascript:" for responding to clicks, it will be better for
you in the long run.

/L
 
T

Thomas 'PointedEars' Lahn

Janwillem said:
Regarding the usage of the javascript: pseudo-protocol, you should read:
http://jibbering.com/faq/#FAQ4_24

I still don't understand why people are continuously calling `javascript:'
a "pseudo protocol". It is part of an URI, and RFC 2396 does not state that
an URI must address a specific protocol. The part before the `:' identifies
an URI scheme, so `javascript:' is simply a not-standardized URI scheme.


PointedEars
 

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,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top