Open html file in a new tab instead of downloading it - html

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.

Related

Saving static HTML page generated with ReactJS

Background:
I need to allow users to create web pages for various products, with each page having a standard overall appearance. So basically, I will have a template, and based on the input data I need the HTML page to be generated for each product. The input data will be submitted via a web form, following which the data should be merged with the template to produce the output.
I initially considered using a pure templating approach such as Nunjucks, but moved to ReactJS as I have prior experience with the latter.
Problem:
Once I display the output page (by adding the user input to the template file with placeholders), I am getting the desired output page displayed in the browser. But how can I now obtain the HTML code for this specific page?
When I tried to view the source code of the page, I see the contents of 'public/index.html' stating:
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
Expectedly, the same happens when I try to save (Save As...) the html page via the browser. I understand why the above happens.
But I cannot find a solution to my requirement. Can anyone tell me how I can download/save the static source code for the output page displayed on the browser.
I have read possible solutions such as installing 'React/Redux Development Extension' etc... but these would not work as a solution for external users (who cannot be expected to install these extensions to use my tool). I need a way to do this on production environment.
p.s. Having read the "background" info of my task, do let me know if you can think of any better ways of approaching this.
Edit note:
My app is currently actually just a single page, that accepts user data via a form and displays the output (in a full screen dialog). I don't wish to have these output pages 'published' on the website, and these are simply to be saved/downloaded for internal use. So simply being able to get the "source code" for the dislayed view/page on the browser and saving this to a file would solve my problem. But I am not sure if there is a way to do this?
Its recommended that you use a well-known site generator such as Gatsby or Next for your static sites since "npx create-react-app my-app" is for single page apps.
(ref: https://reactjs.org/docs/create-a-new-react-app.html#recommended-toolchains)
If I'm understanding correctly, you need to generate a new page link for each user. Each of your users will have their own link (http/https) to share with their users.
For example, a scheduling tool will need each user to create their own "booking page", which is a generated link (could be on your domain --> www.yourdomain.com/bookinguser1).
You'll need user profiles to store each user's custom page, a database, and such. If you're not comfortable, I'll use something like an e-commerce tool that will do it for you.
You can turn on the debugger (f12) and go to "Elements"
Then right-click on the HTML tag and press edit as HTML
And then copy everything (ctrl + a)

How to retrieve the HTML code of a particular site's homepage

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.

How to make PDF from GitHub open in new tab?

I have a pdf file in a GitHub repo and an anchor tag that points to it (<a href="https://github..../file.pdf>link</a>) and when I click it, i download the file automatically.
How to make it open the PDF in a new tab, before downloading it (to the file system, just downloading it within the browser)?
I've tried adding target="_tab" and target="_blank" to the anchor, but all got me the same results?
Is it achieable using just HTML, or I need to use an external JavaScript library?
You shouldn't need to add target="..." whatsoever. I guess you're pointing to the wrong URL. GitHub provides access to the raw file through this URL pattern:
//github.com/<account>/<repo>/raw/<branch>/path/to/file.pdf
Note the raw part in the URL. Check if you got your URL right. A functional example:
Test PDF
You can test it clicking this link. A dialog will open asking you to specify where to download it.

Google Chrome Extensions: Get Current Page HTML (incl. Ajax or updated HTML)

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.

Is HTML source viewed in Firefox the same as original source?

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.