Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to link the 'view-source:' of an external page?

I tried using <a href="view-source:google.com">External Source</a> but that just returns a broken link.

like image 483
Jonny Avatar asked Dec 14 '13 02:12

Jonny


2 Answers

If you're just going to need the HTML source of a webpage, and not anything else, and you're willing to use a server-side language, there is the option of using curl, file_get_contents, or Simple HTML DOM to get the HTML of a website, and then display that on your own page between <code></code> or <pre></pre> tags. This would look something like this in PHP

include("simplehtmldom.php");
$html=file_get_html($url);
echo "<pre>$html</pre>;

Obviously this should be formatted or prettyprinted. Take a look at Google Code prettifier to do this. If you want to get the source of your own page, you could use Javascript, and do this:

var html=document.documentElement.outerHTML;

I'm not sure how that would work for fetching external pages, but you could try an iframe for that, like this

document.getElementById('frame').contentWindow.documentElement.outerHTML;
like image 156
scrblnrd3 Avatar answered Oct 13 '22 01:10

scrblnrd3


The schema/protocol http: is missing:

<a href="view-source:http:google.com">External Source</a>`

Test with the scURIple (scriple):

data:text/html;charset=utf-8,<html><a href="view-source:http:google.com">External Source</a></html>
like image 39
ekim Avatar answered Oct 13 '22 01:10

ekim