Schrift
[thread]2259[/thread]

Script lässt sich nicht auslagern: Javscript



<< >> 4 Einträge, 1 Seite
steinwolf
 2005-06-09 15:07
#24495 #24495
User since
2003-08-04
367 Artikel
BenutzerIn
[default_avatar]
Moins,
ich habe folgendes Problem:
In einer Datei index.php liegen diverse Codeabschnitte, die in Javascript geschrieben wurden. Diese versuche ich nun vollständig auszulagern in eine Datei jscript.js:

<link ref="./js/jscript.js" type="text/javascript">


Teilweise funktioniert dies auch. Doch bei einem Abschnitt eben leider nicht. Eingeleitet wird der Abschnitt mit
Code: (dl )
<script type="text/Javascript">


Im Gegensatz zu den problemlosen Abschnitten:
Code: (dl )
<script language="JavaScript">


Austauschen lassen sich diese Abschnitte auch nicht. Ich schicke einfach mal die ganze Datei:
Code: (dl )
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<html>
<head>
<title>
Suche
</title>
<link href="./css/style.css" rel="stylesheet" type="text/css">
<link ref="./js/jscript.js" type="text/javascript">

<script language="JavaScript">
function changeButton(SendButton)
{
SendButton.value = "Bitte warten...";
SendButton.active = 0;
return true;
}
</script>

<script type="text/Javascript">
// Determine browser and version.

function Browser() {

var ua, s, i;

this.isIE = false; // Internet Explorer
this.isNS = false; // Netscape
this.version = null;

ua = navigator.userAgent;

s = "MSIE";
if ((i = ua.indexOf(s)) >= 0) {
this.isIE = true;
this.version = parseFloat(ua.substr(i + s.length));
return;
}

s = "Netscape6/";
if ((i = ua.indexOf(s)) >= 0) {
this.isNS = true;
this.version = parseFloat(ua.substr(i + s.length));
return;
}

// Treat any other "Gecko" browser as NS 6.1.

s = "Gecko";
if ((i = ua.indexOf(s)) >= 0) {
this.isNS = true;
this.version = 6.1;
return;
}
}

var browser = new Browser();

// Global variable for tracking the currently active button.

var activeButton = null;

// Capture mouse clicks on the page so any active button can be
// deactivated.

if (browser.isIE)
document.onmousedown = pageMousedown;
if (browser.isNS)
document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {

var el;

// If there is no active menu, exit.

if (!activeButton)
return;

// Find the element that was clicked on.

if (browser.isIE)
el = window.event.srcElement;
if (browser.isNS)
el = (event.target.className ? event.target : event.target.parentNode);

// If the active button was clicked on, exit.

if (el == activeButton)
return;

// If the element clicked on was not a menu button or item, close the
// active menu.

if (el.className != "menuButton" && el.className != "menuItem" &&
el.className != "menuItemSep" && el.className != "menu")
resetButton(activeButton);
}

function buttonClick(button, menuName) {

// Blur focus from the link to remove that annoying outline.

button.blur();

// Associate the named menu to this button if not already done.

if (!button.menu)
button.menu = document.getElementById(menuName);

// Reset the currently active button, if any.

if (activeButton && activeButton != button)
resetButton(activeButton);

// Toggle the button's state.

if (button.isDepressed)
resetButton(button);
else
depressButton(button);

return false;
}

function buttonMouseover(button, menuName) {

// If any other button menu is active, deactivate it and activate this one.
// Note: if this button has no menu, leave the active menu alone.

if (activeButton && activeButton != button) {
resetButton(activeButton);
if (menuName)
buttonClick(button, menuName);
}
}

function depressButton(button) {

var w, dw, x, y;

// Change the button's style class to make it look like it's depressed.

button.className = "menuButtonActive";

// For IE, set an explicit width on the first menu item. This will
// cause link hovers to work on all the menu's items even when the
// cursor is not over the link's text.

if (browser.isIE && !button.menu.firstChild.style.width) {
w = button.menu.firstChild.offsetWidth;
button.menu.firstChild.style.width = w + "px";
dw = button.menu.firstChild.offsetWidth - w;
w -= dw;
button.menu.firstChild.style.width = w + "px";
}

// Position the associated drop down menu under the button and
// show it. Note that the position must be adjusted according to
// browser, styling and positioning.

x = getPageOffsetLeft(button);
y = getPageOffsetTop(button) + button.offsetHeight;
if (browser.isIE) {
x += 2;
y += 2;
}
if (browser.isNS && browser.version < 6.1)
y--;

// Position and show the menu.

button.menu.style.left = x + "px";
button.menu.style.top = y + "px";
button.menu.style.visibility = "visible";

// Set button state and let the world know which button is
// active.

button.isDepressed = true;
activeButton = button;
}

function resetButton(button) {

// Restore the button's style class.

button.className = "menuButton";

// Hide the button's menu.

if (button.menu)
button.menu.style.visibility = "hidden";

// Set button state and clear active menu global.

button.isDepressed = false;
activeButton = null;
}

function getPageOffsetLeft(el) {

// Return the true x coordinate of an element relative to the page.

return el.offsetLeft + (el.offsetParent ? getPageOffsetLeft(el.offsetParent) : 0);
}

function getPageOffsetTop(el) {

// Return the true y coordinate of an element relative to the page.

return el.offsetTop + (el.offsetParent ? getPageOffsetTop(el.offsetParent) : 0);
}

</script>

</head>
<body leftmargin="10" topmargin="10">
<center>
<table border="0" width="100%">
<tr>
<td>
<center>
<img src="./img/logo.jpg">
</center>
</td>
</tr>
<tr>
<td>
<!--// leer //-->
</td>
</tr>
</table>
<p>



<noscript>
<h2>Achtung</h2>
<table border=0 width=400 align=justify>
<tr><td>
Sie haben Javascript deaktiviert. Ohne Javascript können Sie die Navigation
von Blinkster nicht nutzen. Bitte aktivieren Sie es in den Einstellungen Ihres Browsers.

</td></tr></table><p>
</noscript>
<table border=0 >
<tr>
<td>

<div id="menuBar">
<a class="menuButton" href="" onclick="return buttonClick(this, 'fileMenu');" onmouseover="buttonMouseover(this, 'fileMenu');">Navigation</a>|<a class="menuButton" href="" onclick="return buttonClick(this, 'editMenu');" onmouseover="buttonMouseover(this, 'editMenu');">Suche</a>|<a class="menuButton" href="" onclick="return buttonClick(this, 'viewMenu');" onmouseover="buttonMouseover(this, 'viewMenu');">Links</a>|<a class="menuButton" href="" onclick="return buttonClick(this, 'toolsMenu');" onmouseover="buttonMouseover(this, 'toolsMenu');">Hilfe</a>|<a class="menuButton" href="" onclick="return buttonClick(this, 'langMenu');" onmouseover="buttonMouseover(this, 'langMenu');">Languages</a>

</div>

<div id="fileMenu" class="menu">
<!-- <div class="menuItemSep"></div> //-->
<a class="menuItem" href="form_login.php">Einloggen</a>
<a class="menuItem" href="form_register.php">Registrieren</a>
<a class="menuItem" href="buglist.php">Bugliste</a>
<a class="menuItem" href="partner.php">Linkpartner</a>
</div>

<div id="editMenu" class="menu">
<a class="menuItem" href="index.php">Einfache Suche</a>
<a class="menuItem" href="">Themensuche</a>
</div>

<div id="viewMenu" class="menu">
<a class="menuItem" href="insert_form.php">Link eintragen</a>
<a class="menuItem" href="locking.php">Lock beantragen</a>
</div>

<div id="toolsMenu" class="menu">
<a class="menuItem" href="help.php">Frequently Asked Questions</a>
<a class="menuItem" href="impressum.php">Impressum</a>

</div>

<div id="langMenu" class="menu">
<a class="menuItem" href=""><img src="./img/de.gif" border=0> Deutsch</a>
<a class="menuItem" href=""><img src="./img/uk.gif" border=0> English</a>
<a class="menuItem" href=""><img src="./img/sp.gif" border=0> Espana</a>

</div>

</td>
</tr>
</table>

<p>



mfg steinwolf
"Did you know? You can use your old motor oil to fertilize your lawn." - Blinkster - Professionelles EDV Forum
esskar
 2006-01-03 02:28
#24496 #24496
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
was soll nicht gehen?
fehlermeldung?
GwenDragon
 2006-01-03 10:39
#24497 #24497
User since
2005-01-17
14761 Artikel
Admin1
[Homepage]
user image
[quote=steinwolf,09.06.2005, 13:07]Im Gegensatz zu den problemlosen Abschnitten:
Code: (dl )
<script language="JavaScript">
[/quote]
Diese HTML-Syntax ist veraltet und Browser werten das language-Attribut nicht aus - neuerer wohl auch nicht mehr. Es ist sinnvoller
Code: (dl )
<script type="text/javascript">
zu schreiben.
[E|B]
 2006-01-03 12:33
#24498 #24498
User since
2003-08-08
2561 Artikel
HausmeisterIn
[Homepage] [default_avatar]
[quote=GwenDragon,03.01.2006, 09:39][quote=steinwolf,09.06.2005, 13:07]Im Gegensatz zu den problemlosen Abschnitten:
Code: (dl )
<script language="JavaScript">
[/quote]
Diese HTML-Syntax ist veraltet und Browser werten das language-Attribut nicht aus - neuerer wohl auch nicht mehr. Es ist sinnvoller
Code: (dl )
<script type="text/javascript">
zu schreiben.[/quote]
Das stimmt nicht ganz. "text/javascript" ist besser, da stimmt ich zu. Aber dennoch wird "JavaScript" noch von allen Browsern ohne Probleme interpretiert.
Gruß, Erik!

s))91\&\/\^z->sub{}\(\@new\)=>69\&\/\^z->sub{}\(\@new\)=>124\&\/\^z->sub{}\(\@new\)=>);
$_.=qq~66\&\/\^z->sub{}\(\@new\)=>93~;for(@_=split(/\&\/\^z->sub{}\(\@new\)=>/)){print chr;}

It's not a bug, it's a feature! - [CGI-World.de]
<< >> 4 Einträge, 1 Seite



View all threads created 2005-06-09 15:07.