Faire appel a un fichier externe dans un code JS

Bonjour,

j ai actuellement un script JS qui en fonctione de la résolution de l’écran:


	<script>		  
if ((screen.width==1024) && (screen.height==768))
	{
	document.write ('<table width="100%" border="0" cellpadding="0" cellspacing="0">');
	document.write ('<tr>');
    document.write ('<td rowspan="6" valign="top"> </td>');
    document.write ('<td width="50" rowspan="6" valign="top" background="images/sidebg_left.gif"> </td>');
    document.write ('<td width="100%" background="images/tabletopbg1.gif"><img src="images/tabletopbg1.gif" width="1" height="4"></td>');
    document.write ('<td width="10" rowspan="6" valign="top" background="images/sidebg_right.gif"><img src="images/sidebg_right.gif" width="10" height="3"></td>');
    document.write ('<td rowspan="6" valign="top"> </td>');
    document.write ('</tr>');
    document.write ('<tr>');
    document.write ('<td width="100%">');
	document.write ('<table width="100%" border="0" cellpadding="0" cellspacing="0">');
    document.write ('<tr>');
    document.write ('<td rowspan="2" background="images/pixi_greyblue.gif"><img src="images/top_logo.jpg" width="150" height="75"></td>');
    document.write ('<td colspan="6" background="images/pixi_greyblue.gif"><img src="images/pixi_greyblue.gif" width="790" height="72"></td>');
    document.write ('</tr>');
    document.write ('<tr>');
    document.write ('<td><img src="images/top_curve.gif" width="22" height="15"><img src="images/top_white.GIF" width="100%" height="15">');
	}
	else if ((screen.width ==1280) && (screen.height==800))
		{
		document.write ('<table width="100%" border="0" cellpadding="0" cellspacing="0">');
		document.write ('<tr>');
	    .
            .
           .
              }

Le problème est quand dans chaucun des cas je dois ajouter le lien suivant:

(avec x variant en onction de la résolution)

Ce lien sera donc prevu pointant vers un fichier spécifique dans chaque if

Mais comment faire?

en effet si je met betement la ligne ci-dessus dans le if, le code n’apprecise pas a cause de l’ouverture, fermeture de balise javascript…

Donc comment intégrer ce fichier dans le code sans utiliser de balises script supplémentaires?

merci d’avance

Au lieu de ça, essaye :

document.write(’<scr’ + ‘ipt’ …)

Et n’oublie pas de faire ça dans ta balise :

(en théorie c’est plus CDATA qu’il faut utiliser, passons)

tu veux dire:
document.write(’<scr=‘ejs_menu_dyn[x].js’>’) ?

c’est quoi le ‘ipt’?

une question bete mais <!-- n’est pas la balise de commentaire en html?

Faut que tu comprennes une chose, sinon tu ne comprendras pas trop ce que je te fais faire :

Dans ta page HTML, tu n’as que du HTML. Le navigateur ne fait qu’interpréter ensuite le contenu de la balise encore moins puisque pour le navigateur ça ferme le script.

Si tu veux que ça passe, tu as plusieurs choix :

  1. un fichier externe, donc un .js, qui contient que du JS, et là document.write(’<script src="’…); fonctionnera
  2. mettre en commentaire HTML : ton script, tu vas l’écrire comme ça :
                <script type='text/javascript'>
                <!--
                tmstpbarreh=Math.round(Math.random()*10000000000);
                document.write('<div style="display:none;"><img src="http://www.smartadserver.com/call/pubimppixel/1125619/'+tmstpbarreh+'?" width="1" height="1" border="0" /><\/div>');
                -->
                </script>		
  1. sans commentaire HTML, casser pour que le navigateur ne l’interprète pas, ou l’écrire avec des entités HTML :

document.write(’<scr’ + ‘ipt src="…" />’);
document.write(’<script src="…" />’);

Voilà.

voila ce que j ai fait donc:


if ((screen.width ==1680) && (screen.height==1050))
			{
			document.write ('<table width="100%" border="0" cellpadding="0" cellspacing="0">');
			document.write ('<tr>');
	      	document.write ('<td rowspan="6" valign="top"> </td>');
	      	document.write ('<td width="50" rowspan="6" valign="top" background="images/sidebg_left.gif"> </td>');
	      	document.write ('<td width="100%" background="images/tabletopbg1.gif"><img src="images/tabletopbg1.gif" width="1" height="4"></td>');
	      	document.write ('<td width="10" rowspan="6" valign="top" background="images/sidebg_right.gif"><img src="images/sidebg_right.gif" width="10" height="3"></td>');
	      	document.write ('<td rowspan="6" valign="top"> </td>');
	      	document.write ('</tr>');
	      	document.write ('<tr>');
	      	document.write ('<td width="100%">');
			document.write ('<table width="100%" border="0" cellpadding="0" cellspacing="0">');
	      	document.write ('<tr>');
	      	document.write ('<td rowspan="2" background="images/pixi_greyblue.gif"><img src="images/top_logo.jpg" width="115" height="60"></td>');
	      	document.write ('<td colspan="6" background="images/pixi_greyblue.gif"><img src="images/pixi_greyblue.gif" width="800" height="70"></td>');
	      	document.write ('</tr>');
	      	document.write ('<tr>');
	      	document.write ('<td><img src="images/top_curve.gif" width="22" height="15"><img src="images/top_white.GIF" width="100%" height="15">');

			bgcolor='#669999';
			bgcolor2='#DDDDDD';
			document.write('<style type="text/css">');
			document.write('.popper { POSITION: absolute; VISIBILITY: hidden; z-index:3; }')
			document.write('#topgauche { position:absolute;  z-index:10; }')
			document.write('A:hover.ejsmenu {color:#FF6600; text-decoration:none;}')
			document.write('A.ejsmenu {color:#000000; text-decoration:none;}')
			document.write('</style>')
			document.write('<div style="position:absolute;top:77px;left:300px;height:30" onmouseover="display()" onmouseout="hide()"><DIV class=popper id=topdeck></DIV>');
			document.write('<scr' + 'ipt src="ejs_menu_dyn.js" />');
			}		  	  

entouré de balise script et /script bien sur.

Ce code fonctionne parfaitement sous mozilla FF mais pas IE6…IE coince au document.write(’<scr’ + ‘ipt src=“ejs_menu_dyn.js” />’); (pareil avec document.write(’’):wink: puisque quand je supprime cette ligne, le reste du code s(affiche, sinon il reste coincé a ce niveau.

C’est normal.

C’est , pas . Ca sera valable sous IE si les devs avaient supportés les balises “vides”, mais c’est pas pour aujourd’hui…