0

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.

Menelaos
  • 23,508
  • 18
  • 90
  • 155
deck
  • 343
  • 2
  • 11

1 Answers1

1

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);
Ray Suelzer
  • 4,026
  • 5
  • 39
  • 55
  • 1
    This no longer works in modern browsers, which appear to have blocked the ability to open data URIs in a new window. – Simon East Sep 03 '21 at 09:31