By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,968 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,968 IT Pros & Developers. It's quick & easy.

view-source:'+document.location'

P: n/a
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.

Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a


John Taylor-Johnston wrote:
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">

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a

"John Taylor-Johnston" <ta******@collegesherbrooke.qc.ca> schreef in bericht
news:3F***************@collegesherbrooke.qc.ca...

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.


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

Jul 20 '05 #3

P: n/a
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:onclick="location.href = 'view-source:' + this.href; return false"">click</a>

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

Still learning ...

Jul 20 '05 #4

P: n/a
John Taylor-Johnston <ta******@collegesherbrooke.qc.ca> writes:
Thanks. Great. Just for fun, ii wanted to put in all inside the href=""

<a href="javascript:onclick="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:onclick='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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

P: n/a
Janwillem Borleffs wrote:
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

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.