473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

view-source:'+document.location'

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
5 12553


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

"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: NiQuil | last post by:
Hello people, I am creating a portal which should be easy maintainable by non-programmers. Thus far people can easyly change the text, set it Bold Italic and Underlined. Also i can set a...
1
by: Rick | last post by:
How would you create a different alt view for each image in the following? <script language="JavaScript"> var i = 1; banner1= new Image(); banner1.src = "image1jpg"; banner2= new Image();...
2
by: relaxedrob | last post by:
Hi All! I have a frameset document and I want each mainFrame document to have the following ability: - be viewed by itself (i.e. without frames if within frameset). - be viewed within frame...
9
by: alu | last post by:
Could someone explain the discrepancies within and between the stated definitions / usage of 'document.location' , 'document.URL' vs. their actual functionality? Should they be read-only when in...
10
by: Geoff | last post by:
I am using the following statement in a script: If (res == 123) document.write (" Blah Blah"); else document.write (" XYZ"); This of course brings up a new page on my site and prints Blah...
5
by: WilliamRLinden | last post by:
Hi world! we are pretty new to JavaScript and have been struggling for now 2 days on this problem ... We would appreciate mercy if anyone can give us some. Basically we are trying to simulate...
1
by: h3ctor83 | last post by:
hello everyone.. can anybody help me? i made an application to upload files to the server.. and after that use ris able to download that file again.. but after downloading the file (specifically...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
I placed a button on a form menustrip for the purpose of causing the horizontal scrollbar of my form to appear so that I can access controls outside of the form's current view (the controls are...
4
by: dasnowball | last post by:
Hi everyone, I'm developing an application using ASP.NET with VB, connected to a SQL Server, running on .NET 2 framework. I am developing a training system where documents are uploaded into the...
4
by: roadiee | last post by:
I am sure this must be common but I can't seem to find how to do it. I have a file structure as follows: php - getimages.php gallery - index.html - image1.jpg - image2.jpg -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.