Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a new tab with custom HTML instead of a URL

I'm making a Greasemonkey script and would like to open a new tab which will not display a URL but some HTML that is part of the script. So basically I want to do something like this (which is obviously not working):

window.open('<html><head></head><body></body></html>'); or GM_openInTab('<html><head></head><body></body></html>'); 

Any hints are welcome!

like image 399
kasper Taeymans Avatar asked May 13 '12 16:05

kasper Taeymans


People also ask

How do I force a link to open in a new tab in HTML?

You can make a HTML link open in a new tab by adding the target=”_blank” attribute. You should insert this after the link address.

How do I get a new tab to open automatically in HTML?

The short answer is: just add a target="_blank" attribute to your links (anchor tags). Now when your visitors click that link, it will open in a new window or tab (depending on which web browser they are using and how they configured that browser).

How do I open a new tab with HTML in Chrome?

You just need an anchor ( <a> ) element with three important attributes: The href attribute set to the URL of the page you want to link to. The target attribute set to _blank , which tells the browser to open the link in a new tab/window, depending on the browser's settings.

How do I make a link open in a new tab instead of a new window?

The first method requires a keyboard and a mouse or trackpad. Simply press and hold the Ctrl key (Cmd on a Mac) and then click the link in your browser. The link will open in a new tab in the background.


1 Answers

You can do this:

var newWindow = window.open();

and then do

newWindow.document.write("ohai");

like image 94
aL3891 Avatar answered Oct 12 '22 22:10

aL3891