Title: JavaScript:window.open() but: &#8220;headers already sent&#8221;
Last modified: August 19, 2016

---

# JavaScript:window.open() but: “headers already sent”

 *  Resolved [thomasgericke](https://wordpress.org/support/users/thomasgericke/)
 * (@thomasgericke)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/javascriptwindowopen-but-headers-already-sent/)
 * English // Deutsch
 * Hi there, // hallo zusammen,
 * I want to call a **JavaScript:window.open()** under certain circumstances on 
   an admin page in a plugin. Therefore, I use the **admin_head**-hook to inject
   some SCRIPT stuff into the header part. Works well. // Ich möchte unter bestimmten
   Umständen auf einer Admin-Seite durch ein plugin einen **JavaScript:window.open()**-
   Aufruf starten. Dazu benutze ich den **admin_head**-hook, um SCRIPT-Kram in den
   Header einzufügen. Das funktioniert auch:
 *     ```
       function uf_add_popup($fake) {
   
             echo "<SCRIPT TYPE='text/javascript'>";
             echo "    function PopUp(URL) {";
             echo "        window.open(URL, '', ...);";
             echo "    }";
             echo "</SCRIPT>";
   
       }
   
       add_action ('admin_head', 'uf_add_popup');
       ```
   
 * The <HEAD> part looks okay. // Der <HEAD>-Teil schaut gut aus.
 * BUT: later in that plugin, I want to call the JS function, which has been defined
   in the header and I need to pass some content (an URL) to it. Unfortunately, 
   I cannot pass additional parameters to **admin_head**, so I tried to simply call
   the JS function. // ABER: später möchte ich in diesem Plugin die JS-Funktion,
   welche im Header definiert wurde, aufrufen und ihr Inhalte (eine URL) übergeben.
   Leider kann man **admin_head** keine Parameter übergeben, also rufe ich die JS-
   Funktion einfach auf:
 * `echo "<JavaScript:PopUp('http://some.url/whatever/')>";`
 * WordPress says: “headers already sent”, so it simply does not work. The problem
   is, “whatever” is some string, I cannot call directly in the FS function above,
   because it’s created dynamically. // WordPress sagt dann: “headers already sent”,
   also klappt das so nicht. Das Problem ist, dass “whatever” ein String ist, den
   ich nicht direkt in der obigen JS-Funktion aufrufen kann, da er dynamisch generiert
   wird.
 * The question is: how to first define a JS function and later call it? // Die 
   Frage ist: wie definiert man erst eine JS-Funktion und ruft sie erst später auf?
 * Thanks for your support. // Danke für die Unterstützung.
 * Thomas

Viewing 1 replies (of 1 total)

 *  Thread Starter [thomasgericke](https://wordpress.org/support/users/thomasgericke/)
 * (@thomasgericke)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/javascriptwindowopen-but-headers-already-sent/#post-1165392)
 * You may close this one. This wasn’t a JS problem. It rather was/is a problem 
   concerning global variables. See:
 * [http://wordpress.org/support/topic/297198](http://wordpress.org/support/topic/297198)

Viewing 1 replies (of 1 total)

The topic ‘JavaScript:window.open() but: “headers already sent”’ is closed to new
replies.

## Tags

 * [header](https://wordpress.org/support/topic-tag/header/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [js](https://wordpress.org/support/topic-tag/js/)
 * [window.open](https://wordpress.org/support/topic-tag/window-open/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [thomasgericke](https://wordpress.org/support/users/thomasgericke/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/javascriptwindowopen-but-headers-already-sent/#post-1165392)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
