"<" in javascript section in masterpage leads to error

This forum is for all Flare related Tips and Tricks.
Have a tip or trick you use while working in Flare? Share it here.
Post Reply
i-tietz
Propellus Maximus
Posts: 1219
Joined: Wed Oct 24, 2007 4:13 am
Location: Fürth, Germany

"<" in javascript section in masterpage leads to error

Post by i-tietz »

Hi there folks,

this is the code of my masterpage:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="3" MadCap:lastHeight="134" MadCap:lastWidth="946">
<head>
	<link href="../Stylesheets/wawi.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
window.onload = bodyanpassenLang;
window.onresize = bodyanpassenKurz;

function bodyanpassenLang () {
	if (document.all)
	{
		if (document.all.headerzeile.style.getAttribute)
		{
			var hoehe = document.all.headerzeile.offsetHeight + 38;
			if (document.all.topic.style.setAttribute)
			{
				document.all.topic.style.setAttribute("paddingTop", hoehe);
				document.all.headerzeile.style.setAttribute("top", 28);
				document.all.headerzeile.style.setAttribute("zIndex", 1);
				var breite = document.body.offsetWidth;
				document.all.headerzeile.style.setAttribute("width", breite);
				document.all.toolbaroben.style.setAttribute("visibility", "visible");
				document.all.toolbaroben.style.setAttribute("left", 0);
				document.all.toolbaroben.style.setAttribute("top", 0);
				document.all.toolbaroben.style.setAttribute("right", 0);
				document.all.toolbaroben.style.setAttribute("zIndex", 2);
				document.all.toolbaroben.style.setAttribute("width", breite);
			}
		}
	}
	var adresse = document.URL;
	var hatmarke = adresse.split("#");
	anzahllinks = document.anchors.length;
	if (document.anchors)
	{
		for (var zaehler = 0; zaehler < anzahllinks; zaehler++)
		{
			alert("hi there");
		}
	}
}

function bodyanpassenKurz () {
	if (document.all)
	{
		if (document.all.headerzeile.style.getAttribute)
		{
			var hoehe = document.all.headerzeile.offsetHeight + 38;
			if (document.all.topic.style.setAttribute)
			{
				document.all.topic.style.setAttribute("paddingTop", hoehe);
				document.all.headerzeile.style.setAttribute("top", 28);
				document.all.headerzeile.style.setAttribute("zIndex", 1);
				var breite = document.body.offsetWidth;
				document.all.headerzeile.style.setAttribute("width", breite);
				document.all.toolbaroben.style.setAttribute("visibility", "visible");
				document.all.toolbaroben.style.setAttribute("left", 0);
				document.all.toolbaroben.style.setAttribute("top", 0);
				document.all.toolbaroben.style.setAttribute("right", 0);
				document.all.toolbaroben.style.setAttribute("zIndex", 2);
				document.all.toolbaroben.style.setAttribute("width", breite);
			}
		}
	}
}
</script>
</head>
<body id="topic">

<div id="toolbaroben" class="toolbardiv">
	<MadCap:topicToolbarProxy class="aw_toolbar" />
</div>
<MadCap:bodyProxy />
</body>
</html>
"Headerzeile" is the id of a div that contains the H1 and a few links - the div is fixed at the top, beneath the topic toolbar and both divs don't scroll.

The text editor and the error message on preview and build look like this:
compare_in_js_section.png
- The "<" starts the funny outfit of the text in the text editor, the ">" puts an end to it.
- If I insert the script in any other place (body, separate file), either I get other error messages or the topic toolbar isn't there: The topic toolbar is generated, displayed and handled by a MC js. My js seems to interfere ...

Apart from the syntax bugs in the loop (picture, not code): Does anybody have a way out for me? I need a loop at that point ...

Thanx!

Inge
You do not have the required permissions to view the files attached to this post.
i-tietz
Propellus Maximus
Posts: 1219
Joined: Wed Oct 24, 2007 4:13 am
Location: Fürth, Germany

Re: "<" in javascript section in masterpage leads to error

Post by i-tietz »

UPDATE:
If I try it the other way around (don't even know if that's a correct construction ... ), it look like this in the source code of a topic in the built help:

Code: Select all

	if (document.anchors)
	{
		for (var zaehler=anzahllinks;zaehler>0;zaehler--)
		{
			alert("hi there");
		}
	}
The error message I get when opening a topic:
greaterThan_in_js_section.png
You do not have the required permissions to view the files attached to this post.
LTinker68
Master Propellus Maximus
Posts: 7247
Joined: Thu Feb 16, 2006 9:38 pm

Re: "<" in javascript section in masterpage leads to error

Post by LTinker68 »

Well, I don't read German, assuming that's what that is, so I don't know what the error is say, but have you tried replacing < with < and replacing > with >? Or maybe putting a CDATA tag around the < and >? I'm not sure if that last one will work, and I can't see the top and bottom of the code block to see if it's properly incased in script tags. You could also try putting the Javascript code into an external JS file and referencing to it in the topic.
Image

Lisa
Eagles may soar, but weasels aren't sucked into jet engines.
Warning! Loose nut behind the keyboard.
i-tietz
Propellus Maximus
Posts: 1219
Joined: Wed Oct 24, 2007 4:13 am
Location: Fürth, Germany

Re: "<" in javascript section in masterpage leads to error

Post by i-tietz »

comment tags ...
It takes comment tags ...
Flag
Jr. Propeller Head
Posts: 1
Joined: Wed Jan 14, 2015 7:17 am

Re: "<" in javascript section in masterpage leads to error

Post by Flag »

Hi,

I'm running in the same bug.
Does anyone know what i-tietz meant by this comment tag thing?

EDIT:
Ok, I found what's going on...
Use

Code: Select all

<script type="text/javascript">/*<![CDATA[*/
//your code
/*]]>*/</script> 
Or use the Insert > script menu and paste your code.
Post Reply