search

Home  >  Q&A  >  body text

How nginx returns a piece of js that can be executed on the client

I want to use nginx configuration to automatically return a piece of js when accessing a certain URL, such as alert("some message")

I want to achieve this through the following configuration

location /foo {
          default_type application/javascript;
          return 200 '<script>alert("hello");</script>';
 }

But the actual access in the browser only returns text

<script>alert("hello");</script>

No dialog box pops up. Can nginx support returning js? How to configure it correctly?

PHPzPHPz2812 days ago794

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:17:05

    text/html

    reply
    0
  • Cancelreply