/    Sign up×
Community /Pin to ProfileBookmark

multiple javascripts??

Not sure how to get multiple scripts on a page? Here’s an example if I use both of these how do they go and where in order to both work?

#1:
<html>
<head>
<title>Today’s date example</title>
</head>

<body>
<script language=”JavaScript1.2″>

/* Creates a date object and leave it blank to use the default of today’s date */

var today = new Date;

/* Writes the date to the browser window */
document.write(today);

</script>

</body>
</html>

#2:

<html>
<head>
<title>Send visitors from outside to the homepage</title>
</head>

<body>
<script language=”JavaScript1.2″>

/* If linked to from outside of mywebsite.com, send the user to the
homepage. To use this script replace “mywebsite.com” with your own
virtual domain *
/

/* Note that “mywebsite.com” is used for illustration purposes only
and that this domain may actually exist in the near future *
/

if (document.referrer == “” || document.referrer.indexOf(“mywebsite.com”) == -1)
window.location = “http://www.mywebsite.com“;

</script>

</body>
</html>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JPnycNov 10.2005 — You don't need 2 sets of script tags. Just put it all in one.
Copy linkTweet thisAlerts:
@earth2macauthorNov 10.2005 — Do you mean just the script code ie:

<html>

<head>

<title>Today's date example</title>

</head>

<body>

<script language="JavaScript1.2">

/* Creates a date object and leave it blank to use the default of today's date */

var today = new Date;

/* Writes the date to the browser window */

document.write(today);

/* If linked to from outside of mywebsite.com, send the user to the

homepage. To use this script replace "mywebsite.com" with your own

virtual domain *
/

/* Note that "mywebsite.com" is used for illustration purposes only

and that this domain may actually exist in the near future *
/


if (document.referrer == "" || document.referrer.indexOf("mywebsite.com") == -1)

window.location = "http://www.mywebsite.com";

</script>

</body>

</html>
Copy linkTweet thisAlerts:
@LeeUNov 10.2005 — It would be better to put the entire script in an external file (w/o the script tags). Be sure to use the ".js" file extension. Then place this link in the head section of the page you want to use it on:

[CODE]<script type="text/javascript" src="yourfile.js"></script>[/CODE]

You can put the date part into a function and call it from the page. Place this in the external file:

[CODE]
function myDate() {
var today = new Date;
document.write(today);
}
[/CODE]


Then place this on the page where you want the script:

[CODE]
<script type="text/javascript">
<!--
myDate()
//-->
</script>
[/CODE]
×

Success!

Help @earth2mac spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...