Bonjour,

je voudrais passer à un script php le nom d'une fonction javascript à executer. Cette fonction a une chaîne de caratères comme paramètre.

Bref, je voudrais appeler:

execute.php?function=toto('test')

et que le javascript execute toto('test')

Le code suivant ne marche pas:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
<?php
 
$function = ''; if(isset($_GET['function'])) $function = $_GET['function'];
 
$output = '<html>';
$output .= '<head>';
 
$output .= '<script language="javascript">';
$output .= 'function toto(text)';
$output .= '{ alert(text); }';
$output .= '</script>';
 
$output .= '</head>';
 
//$function = 'toto(\'test\')';
 
$output .= '<body onload="'.$function.';">';
$output .= $function;
$output .= '</body>';
$output .= '</html>';
 
echo($output);
exit;
 
?>

Par contre, si je décommente la ligne $function = 'toto(\'test\')';, ça fonctionne.

Qu'est-ce qui ne va pas dans le passage de mes ' ?

Merci

Jérôme