/    Sign up×
Community /Pin to ProfileBookmark

Choosing Script By Script!!

[B]I need your help.[/B]
I have a basic knowledge of JS and I’m trying to write a script at the end of the body, before </body>, which chooses conditionally between two other scripts and it depends to the webpage format (secure or not secure). But I don’t know how to start.

This may make sense more about what I’m trying to say:

<script>

If “page is secure or an SSL type” DO

<script A></script A>

else

<script B></script B>

</script>

If you have better idea or something other than scrip, I would appreciate your help.[B]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@dungsportOct 04.2006 — The following is in javascript, PHP tags just makes it look better ?
[code=php]<script>
if (location.href.indexOf('https://')==0) { // secure
// do something here for secure page
} else { // insecure
// do something here for insecure page
}
</script>[/code]


If you would like to load external script instead of writing some code for each case, please do as follows:

[code=php]<script>
if (location.href.indexOf('https://')==0) { // secure
document.write('<script src="secure.js"></script>');
} else { // insecure
document.write('<script src="insecure.js"></script>');
}
</script>[/code]


That's it ?
×

Success!

Help @bolsa 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 5.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...