How to open a tab and display text in blank page [duplicate] - javascript

This question already has answers here:
Open window in JavaScript with HTML inserted
(8 answers)
Closed 7 years ago.
When the user click somewhere, I want the browser to open a new tab and display the text I want him to.
I want something exactly like a link with a blank target to a text file on my server, except that the text is generated on the client side by my script, so no interaction with the server.

Assuming that you are just looking to display text in a file. You can build a string with Javascript and then open a new window with that code below.
Please note, that popup blockers do not like window.open.
var str = 'hello world';
window.open('data:text/plain;charset=utf-8,' + str);

Related

How to detect active page / input box in browser extension? [duplicate]

This question already has answers here:
How to access the webpage DOM/HTML from an extension popup or background script?
(2 answers)
How to determine which html page element has focus? [duplicate]
(5 answers)
Closed last month.
From the browser extension (running in the background) I would like to detect that user placed the mouse pointer in the password input box and trigger some event(s) e.g. pop-up an icon to prompt the user for action (autofill the box with the password, provide some options, etc) similarly as eg. 1password does in the screen capture below.
How this can be accomplished e.g. in JavaScript?

How do I open and type in another Tab Using only Javascript [duplicate]

This question already has answers here:
Open a URL in a new tab (and not a new window)
(33 answers)
Closed 4 years ago.
I need to open a URL, then type there, and I was wondering if you could do that in javaScript, how, and if not, are there any other languages I can do that in. Remember: No HTML Or CSS and I use Opera.
Thanks, - Beginning Coder
Elaborating, I am trying to open my email or Gmail ( I can do that part) and then type in who it is to, etc. Please Help. + Thanks for the feedback and tips though
The first part of your question (opening a new tab) is a duplicate of this question:
StackOverflow
I'm not entirely sure what you mean by "write," but I answered what I think you're asking.
As for writing into a new window/tab with JS, you can do that 2 ways:
Open a url on your website in a new window/tab
Make a new window and use document.write()
Tutorial: W3 Schools
Now that I know what you want to do specifically, you can do this:
window.open("https://mail.google.com/mail/u/0/#inbox?compose=new");
to open gmail in a new window/tab. You cannot write into any elements in that window (the subject line, for example) with JS because the same-origin policy does not allow it (you do not own google.com). Thus, you cannot accomplish what you want to do unless you are writing into a new window on your own website or file directory.
This StackOverflow post tells you how to set up a mailto that can auto set the subject and body. It's not exactly what you want, but maybe you could adapt it.
To open a new tab through JavaScript you can use window.open("link").
And to type in you could make a form in HTML and get the value from that form: document.getElementById("form id from html").value and store it in a variable so you can use it as link in windows.open;

How to launch a local .html file as a pop-up? [duplicate]

This question already has answers here:
Open a local HTML file using window.open in Chrome
(3 answers)
Closed 4 years ago.
I am wondering what I can add to make an .html or .htm file create a pop-up window instead of creating a normal window and load the content in that window. Is there a way to do this? I have no idea, thanks.
link text
target="_blank" makes the link open in a new window, now a new tab

how to add target blank to an href.location hyperlink [duplicate]

This question already has answers here:
Open a URL in a new tab (and not a new window)
(33 answers)
Closed 5 years ago.
I'm trying to get a link in javascript to open a url in a new tab. I've found a number of posts for target="blank" using attribute and a couple other ways but can't seem to get it to work. Basically, if v_virt = "invoices" I just need the url to open in a new tab. Does anyone know the proper syntax?
if(v_virt=="invoices"){
location.href=('https://www.example.com/invoices/invoice?ProjectID=[#field:ProjectID]&InvoiceID=[#field:InvoiceID]', '_blank');
}
You have to use window.open() rather than location.href.
location.href changes the URL of the current page;
window.open() opens a new pop-up window navigated to the specified page.
For example:
window.open('https://www.example.com/invoices/invoice?ProjectID=[#field:ProjectID]&InvoiceID=[#field:InvoiceID]');

Automatiaclly crop website before printing the page [duplicate]

This question already has answers here:
remove url and print text from the printed page
(4 answers)
Closed 7 years ago.
I have a HTML file that triggers print() when you click a button. How do you crop the page so the site name and url does not show up?
You cant, including URL and/or title is up to the browsers print dialog.

Categories

Resources