serenodo
Messages postés15Date d'inscriptiondimanche 30 avril 2017StatutMembreDernière intervention 6 mars 2020
-
Modifié le 30 avril 2017 à 15:14
serenodo
Messages postés15Date d'inscriptiondimanche 30 avril 2017StatutMembreDernière intervention 6 mars 2020
-
30 avril 2017 à 22:42
Bonjour,
J' aimerai savoir s'il est possible d'inclure un fichier js dans une fonction ?
Voici un bout de mon code
function store( data )
{
data[ 0 ] = new Stock( "Athena",
"message d'erreur imputation",
"Messages_bloquants/Message_Erreur_Imputation.docx" );
data[ 1 ] = new Stock( "Athena",
"Changer_numero_imputation.",
"Athena/Changer_numero_imputation.txt" );
}
J 'aimerai déplacer les lignes de code "data......." dans un autre fichier , et le rapeler dans la function store( data)
voici le code en entier
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 transitional//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<title>Support SSPG</title>
<link href="code.css" type="text/css" rel="stylesheet" />
<script language="Javascript">
<!--
function afficher()
{
document.writeln( '<h3><a href=' + this.url + ' rel="nofollow noopener noreferrer" target="_blank">' + this.titre
+ '</a></h3><p class=noindent>' + this.keyword + '<br><a href=' + this.url + ' rel="nofollow noopener noreferrer" target="_blank">' + this.url + '</a></p>\n' );
}
function Stock( titre_in,keyword_in,url_in )
{
this.titre = titre_in;
this.keyword = keyword_in;
this.url = url_in;
this.afficher = afficher;
}
function store( data )
{
data[ 0 ] = new Stock( "Athena",
"message d'erreur imputation",
"Messages_bloquants/Message_Erreur_Imputation.docx" );
data[ 1 ] = new Stock( "Athena",
"Changer_numero_imputation.",
"Athena/Changer_numero_imputation.txt" );
}
/* Cette fonction réécrit entièrement la page web pour y afficher les résultats */
function rechercher( chaine )
{
var trouved = 0;
chaine = chaine.toUpperCase();
var data = new Array();
store( data );
document.writeln( "<html><head><title>Résultats de la recherche</title><link href='/common/style.css' rel='stylesheet' type='text/css'></head>" );
document.writeln( "<body class='article'><div class='alone'>" );
document.writeln( "<h1>Résultats de la recherche</h1>" );
for( var i=0; i<data.length ; i++ )
{
if(( data[i].titre.toUpperCase().indexOf( chaine ) != -1 )
|| ( data[i].keyword.toUpperCase().indexOf( chaine ) != -1 )
|| ( data[i].url.toUpperCase().indexOf( chaine ) != -1 ))
{
data[i].afficher();
trouved ++;
}
}
if( !trouved )
{
document.writeln( "<p style='color: red; font-weight: bold;'>Aucune réponse n'a été trouvée pour ce mot clé dans les pages informatiques de ce site.</p>");
}
document.writeln( "<p style='color: blue; font-weight: bold;'>"+trouved+" réponse(s) trouvée(s) pour le mot-clé "+chaine);
document.writeln( "</p><hr><form><input type='button' value='Nouvelle recherche ?' OnClick='window.location=\"moteurRecherche.html\"'></form></div>" );
document.writeln( "</body></html>" );
document.close();
}
//-->
</script>
</head>
<body>
<center><h2>Moteur de recherche assistance SSPG </h2></center>
<div align="center" style="text-align: center; margin: 15px; padding: 15px; font-family: monospace; font-size: 14pt; font-weight: bold;">
écrit en JavaScript.
</div>
<p>
Il s'agit d'un moteur minimal : tapez <B>un seul</B> mot-clé. Les accents sont autorisés ; les symboles
(? = + ; - , * $ ! #) ne le sont pas. Si vous ne tapez rien, toutes les pages de ce site seront listées.
</p>
<form name="rech" OnSubmit="rechercher( document.rech.champ.value );">
<input type="text" name="champ" size="70"><BR>
<input type="submit" name="valide" value="Rechercher">
</form>
<noscript><p>
Votre navigateur ne reconnaît pas le JavaScript, le script de recherche ne pourra pas marcher.
</p></noscript>
</div>
<!-- Début Script Weborama -->
<div align="right">
<script language="javascript">
<!--// page recherche
WEBO_ZONE=200;
WEBO_PAGE=2;
webogold_ok=0;
//-->
</script>
<script language="javascript" src="http://script.weborama.fr/gold.js"></script>
<script>
<!--//
if( webogold_ok == 1 )
{
webogold_zpi( WEBO_ZONE, WEBO_PAGE, 10194 );
}
//-->
</script>
</div>
<!-- Fin Script Weborama -->
</body>
</html>
serenodo
Messages postés15Date d'inscriptiondimanche 30 avril 2017StatutMembreDernière intervention 6 mars 2020 30 avril 2017 à 15:56
Bonjour karamel,
j 'ai refais le fichier js avec la fonction , et je l 'ai appelé en début balise head
<script type = 'text/javascript' src="/home/ecrivain77/Documents/SSPG_DOC/SSPG/data.js">
Mais pas réponse lors de l'appel du fichier dans la fonction
function rechercher( chaine ) {
var trouved = 0;
chaine = chaine.toUpperCase(); var data = new Array(); store( data );
serenodo
Messages postés15Date d'inscriptiondimanche 30 avril 2017StatutMembreDernière intervention 6 mars 2020 30 avril 2017 à 16:07
Bonjour,
Je pense que je me suis mal expliqué
je voudrais déplacer toute la function store(data), dans un fichier externe en .js, et le rappeler au début de la function rechercher( chaine )
car la commande store(data) dans la function rechercher fait appel à la function store(data) qui contient des données renseignées manuellement
@karamel
Messages postés1838Date d'inscriptionvendredi 9 mai 2008StatutModérateurDernière intervention19 août 2023148 30 avril 2017 à 18:36
a ce moment la autant laisser la fonction tel quel il faut juste la mettre dans un fichier js, le fichier contiendra uniquement la fonction et c'est tout .
Vous n’avez pas trouvé la réponse que vous recherchez ?
serenodo
Messages postés15Date d'inscriptiondimanche 30 avril 2017StatutMembreDernière intervention 6 mars 2020 30 avril 2017 à 22:42
Bonjour,
Incroyable mais vrai maintenant cela fonctionne.
J'ai tout refais le code, je pense que j'avais un bug dans le code depuis le début.
Merci pour ta patience.