Does Firefox's "view source" option display the same HTML page code that I would obtain by opening the HTML file in the server's file system? (e.g with notepad), or is it modified?
No, its not de original source code. Firefox parses the source code before like beautifulsoup does.
You can view the original source code in linux with wget url.
Besides that it has syntax highlighting and the urls are clickable, the view source has the original content.
So if you view source and copy the whole thing and paste it in notepad is the same result as opening the actual webpage in notepad.
If you use FireBug, the source is modified, otherwise Firefox shows the original source
The 'view source' will show the actual source code, as sent by the server. Formatting is left as is, but urls will be clickable and open a new window with the resource referred to.
The 'view generated source' will show the source code as currently displayed on the page, thus containing modifications to the DOM after the page was sent, usually done with Javascript.
Related
I want to get the HTML code of a particular site. It asks me to register myself first so that I can be redirected to their home page. Now, my question is: is it possible to retrieve the HTML code of the desired page just by choosing option ‘View Page Source’ which appears on right click? Is there any other way to fetch the HTML code?
There are multiple ways of getting the HTML source code of a page
One way, as you already know is by viewing the page's source code.
If you Right Click -> View Page Source or just press Ctrl + U you will view the source code in your browser
If you are using linux, you can use wget to get the source code.
Just open up a console and type wget www.somewebsite.com and you will get the HTML source code along with any CSS and JS links.
However, you cannot get the PHP code using any method unless you have FTP access to the server
Yes it is possible to view HTML via 'View page source' or you could use PHP as mentioned in the comments.
'usign php yes php.net/manual/en/function.file-get-contents.php –
Vitorino fernandes'
You could also let a website and or program do it for you but it's trustability depends on the site and or program,
Do note it is NOT possible to view the PHP source since that is server-side.
Using any browser, the "View Page Source" option will show you the source of the page, as received by the browser (which may be different then the source currently displayed). You also have the option of using the File > Save Page As (or similar) menu option to save a copy of the html code of the page from the browser.
It is also possible to use command line tools like curl and wget to download the page to your local machine. Those tools provide options to send data (such as cookies or headers to identify yourself) along with the request.
For my Trac plugin, I have made an export script which converts contents to a different format. The result is an HTML code.
When I click the link, some browsers open the HTML code in a new tab, while others offer to download it as a .print file, depending on their specific settings I think. Opening this .print file shows the same HTML page as opening it directly, but locally instead of from the server.
How can I force it to always open in a new tab?
I think it might be a mimetype issue. If it is, which mimetype can I use to tell the browser to open the HTML code directly? I am currently using text/html as mimetype.
EDIT: some more info
To give some more insight, adapting from a comment of mine below:
I do not create the link myself. The link is provided by Trac, the bug tracking software the plugin is for, and what I do is implement the method that creates the HTML code and let it return the HTML code along with the mimetype. Trac then returns the HTML code either as a file, or as a new tab, when clicking on that content conversion link. What I am searching for is a possibility to specify in the HTML code or mimetype that it gets opened in a new tab directly.
Maybe there is some kind of mimetype specifying the (HTML) text as an HTML web document instead of HTML file (if that distinction even exists).
Or an HTML/XML header or doctype specifying whether it gets downloaded or opened by a browser. I think the browser need to get that information from somewhere.
Or maybe there is an option to set in Trac.
I hope these ideas of mine about what could exist can help those of you who are versed with either or some of these to find a solution. I could not find a solution through my research yet.
If you have a link that "directly" opens (not in a new tab) and you want it to open a new tab, one way of doing it is
This will create a blank page, then paste the link there automagically and thus you will have a new tab with the desired page.
Is there a way to (without inspecting elements via chrome dev tools) resend the http request that displays a pages's source code?
I load some dynamic HTML, and it looks fine in my inspector, but I'd like to see it in the source code view. Is there a way to tell my browser to resend the source but with the dynamic html included?
Nope.
The devtools browse the dom, not the source. If you manipulated the dom with js, it will no longer match the source.
Requested workaround:
Open devtools
Right-click the <html> element and select 'Edit as HTML.'
Hit Ctrl+A followed by Ctrl+C
Open your editor of choice and paste code
This will be a snapshot of the dom.
You can view the source code of ajax/xhr requests (if that's what you're looking for). Try Chrome using the dev tools. Go to the Network tab, turn on the recording button, then make your ajax call. It should pop up on the left. You can then use the "Response" tab to see the actual source code that was sent to you.
You can also right-click a network request and do "Replay XHR" to re-send your ajax request. Your script probably won't process it, though.
I'm not sure if this is exactly what you are looking for, if it isn't, can you clarify? "Dynamic HTML" is a bit ambiguous.
(FYI The DOM is source code that has been modified by the browser. The original source code is under right click > view page source.)
In my Google Chrome extension, I need to be able to get the current page HTML, including any updated Ajax HTML (unlike the browser's View Source command, which doesn't update it).
Is there a way to get it as a string in my Extension?
Suppose my extension is a right-click context menu called "View Actual HTML Source" which should print the current HTML to the console, or maybe count the number of certain tags there. I wasn't able to find an easy answer to this.
You can get the current state of the DOM as HTML programmatically using document.documentElement.innerHTML
Or just use Developer Tools
I followed the exact solution here, and this gave me the Page Source HTML:
Getting the source HTML of the current page from chrome extension
The solution is to inject the HTML into the Popup.
i have recently started using Senchs extJS.. when we see the source file it only displays what ever is the written code, but what the style has applied or any script that added later is not there in the "View Source"
Same for AJAX, when we load anything in any container, it is not there...
but if we're using Chrome and we inspect the element, it show everything....
WHY this behavior?
View Source in browsers typically only displays the downloaded source without running anything at all (including any JS that would modify the DOM). In fact, at least Chrome will create a separate request when you view source to get that code.
As for the reason why, I'm not sure exactly. This is just the standard and is the way that "view source" has worked for long before I was ever a web developer. It is similar to doing a raw HTTP request (i.e. you just get the source; nothing runs to change it). The term "Source" indicates the origin of what you have received, unmodified (think "source code.")
Because that's just how it works. View source only shows the page when it was first served up to the browser.