I tried using External Source but that just returns a broken link.
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;
The schema/protocol http: is missing:
External Source`
Test with the scURIple (scriple):
data:text/html;charset=utf-8,<html>External Source</html>
As an alternative to outputting everything in a <pre> block, consider returning a different content type. In your response headers:
Content-Type: text/plain
Then, you can simply return the HTML content and it will be displayed as plain-text in the browser.
Related
Can somebody kindly suggest the proper way to use JSoup on a website like "https://network.axial.net/a/company/business-team-san-francisco/"?
This website has a lot of Javascripting, and no matter what I do {documentObj.body().data(), documentObj.html(), connectionObj.response().body(), Jsoup.connect(urlStr).userAgent("Mozilla").data("name", "jsoup") etc.}, I am not able to recover the html that is rendered in a browser.
This is not possible with JSoup. The intent of JSoup is to parse HTML only.
If you are looking for something that can evaluate Javascript to return the resulting DOM, you might want to look at either Selenium or HtmlUnit.
I'm using an ASP classic app to create HTML <table>...<td> cells with SVG drawings encapsulated in an <object> tag, which works fine. Here is what the <object> looks like:
<object data="http://myserver.com/foo.asp?svgdata=data/bar.xml" type="image/svg+xml" border="1">Browser unsupported</object>
When the page loads, <object> issues a GET to the server (and ASP), with a parameter value in its data= parameter. My challenge is I'd like to create the svgdata= argument on the fly, and send a lengthy data payload in it to the server. So I'm hoping I could use POST to do so, since GET is size-restricted.
Is there a way to coerce the <object> to issue POST instead of GET? Assuming I could navigate the particularities of passing a correctly constructed svgdata= attribute.
Note, the final form of this is a pure HTML + SVG document in the browser DOM, it's not a Form or interactive otherwise.
Thank you, Stackoverflow readers!
Facebook like button (XFBML) used this
<fb:like send="true" width="450" show_faces="true"></fb:like>
Clearly the <fb></fb> is a tag, XML will accept it but it's not HTML. So is it normal that the browser keep it in the document?
What kind of programming technique is this called? Is it the right way? Or just another way to create a hidden element and replace the id="fb" ?
What is the :something in <fb:like> stands for? How to access it with javascript?
This is XHP!
XHP is a PHP extension created by Facebook.
It makes PHP understand XML nodes, so you can write something like this (from their own example):
<?php
$href = 'http://www.facebook.com';
echo <a href={$href}>Facebook</a>;
?>
XHP also allows you to create PHP classes, which can be used in your markup. So the <fb:like /> node is actually turned into a PHP class at compile time. The definition of the class probably looks like this:
<?php
class :fb:like extends :x:element {
...
}
You can read more about it in the link to Github above, and on the creators blog which is all about XHP.
So to answer your questions:
will not be processed by the browser, but by XHP. XHP turns it into PHP objects, which lastly turns it into valid HTML tag(s). This is true when using XHP, but it is also possible for us to use the same tag, without XHP. I'm guessing this is just a matter of parsing the tag in javascript and sending the variable to the API, which probably uses API to recreate the structure, and send back the HTML.
Not really a technique, but a unique thing that Facebook has developed to make their lifes working with PHP easier.
Again, when it is returned to the browser, it has been transformed by XHP (after sending it to Facebook through javascript). Try looking at the rendered version - it looks different than the simple <fb:like> tag.
The website use ajax to load some data.When DocumentCompleted,I only get the html code without ajax data.
How to get the ajax data through webkit.net?
Thanks.
I've just recently fought with this myself and have what should be a working solution. I've not tried it with ajax, but I have used it after creating and appending DOM elements from C# and it produces the full code where DocumentText only produces the original unmodified HTML.
var fullHTML = webKitBrowser1.StringByEvaluatingJavaScriptFromString("document.getElementsByTagName('html')[0].outerHTML")
The only limitation to this method that I've seen is that it does not include the doctype tag if there is one, but everything else is there.
<label for="abc" id="xyz">http://abc.com/player.js</xref>?xyz="foo" </label>
is ignoring
</xref> tag
value in the browser. So, the displayed output is
http://abc.com/player.js?xyz="foo"
but i want the browser to display
http://abc.com/player.js</xref>?xyz="foo"
Please help me how to achieve this.
It isn't being ignored. It is being treated as an end tag (for a non-HTML element that has no start tag). Use < if you want a < character to appear as data instead of as "start of tag".
That said, this is a URL and raw <, > and " characters shouldn't appear in URIs anyway. So encode it as http://abc.com/player.js%3C/xref%3E?xyz=%22foo%22
You should do it like this
"http://abc.com/player.js%3C/xref%3E?xyz=foo"
Url should be encoded properly to work as valid URL
Use encodeURI for encoding URLs for a valid one
var ValidURL = encodeURI("http://abc.com/player.js</xref>?xyz=foo");
See this answer on encodeURI for better knowledge.
I misunderstood the question, I thought the URI was to be used elsewhere within JavaScript. But the question pretty clearly states that the URI is to just be rendered as text.
If the text being displayed is being passed in from a server, then your best bet is to encode it before printing it on the page (or if you're using a template engine, then you can most likely just encode it on the template). Pretty much any web framework/templating engine should have this functionality.
However, if it is just static HTML, just manually encode the the characters. If you don't know the codes off the top of your head, you can just use some online converter to help, such as something like:
HTML Encode/Decode:
http://htmlentities.net/
Old Answer:
Try encoding the URI using the JavaScript function encodeURI before using it:
encodeURI('http://abc.com/player.js</xref>?xyz="foo"');
You can also decode it using decodeURI if need be:
decodeURI(yourEncodedURI);
So ultimately I don't think you'll be able to get the browser to display the </xref> tag as is, but you will be able to preserve it (using encodeURI/decodeURI) and use it in your code, if this is what you need.
Fiddle:
http://jsfiddle.net/rk8nR/3/
More info:
When are you supposed to use escape instead of encodeURI / encodeURIComponent?