Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Externalizing JS and adding to the .page
acezone
Hi All,
This may sound weird (or stupid) ... but I would like to know as in how to externalize JS and then using the same in either at site properties or at page properties level from SitePublisher.
Requirement is such that as I preview the page below code should be embedded:
<head>
<script language="JavaScript">
var urlPrefix = '<valueof bean="HostName.servername"/>' ;
function generateCDNURL(image,urlSufix)
{
var image = document.getElementById(image);
image.src=urlPrefix+urlSufix;
}
</script>
<script language="JavaScript" type="text/javascript">
// begin click tracking code
var ip="123.1.2.3";
var site=1; // site specific id number
var page=location.href;
function runTheCGI(url, isFlash)
{
if(isFlash != 12)
{
isFlash = 1;
}
if(isFlash == 12)
{
isFlash = 0;
}
var xh;
if(window.XMLHttpRequest) {
xh= new XMLHttpRequest();
}else if(window.ActiveXObject) {
xh = new ActiveXObject("Microsoft.XMLHTTP");
}
if(xh){
xh.open("GET", "/cgi_root/tracking.cgi?site=" + site + "&addr=" + ip + "&page=" + page + "&url=" + url + "&isFlash=" + isFlash, false);
xh.send(null);
}
}
// modifies all links in page to call function to log
function modifyLinks()
{
for(var i = 0; i < document.links.length; i++)
{
document.links
.onmousedown = new Function("runTheCGI(this.href,12);");
}
}
// end click tracking code
</script>
</head>
Any pointer will be great a great help.
Regards,
Ace
Find more posts tagged with
Comments
Stokes
Ace,
Are you saying it has to be an inline
<script/>
element? If it can be an external .js file, you simply include it as a resource in the page properties, or you can do the same in the site properties instead and that resource will be included on every page in the site.
If it needs to be inline script, then in 3.1 you can use the page scoped variable
head_injection
. A component external (or I assume a page pre-controller) can contribute values to that page-scoped variable and its contents will be put in the
<head>
section of the HTML.
Stokes.