Solved

HTML not rendering in Safari, Chrome

Posted on 2010-08-13
5
1,359 Views
Last Modified: 2012-05-10
Hi All,

My html page can render and display fine in IE and FF but not so much in Safari and Chrome. I'm guessing that something may be wrong with my javascript. Any help or direction with this is much appreciated.

Thanks!
tone


<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>H41 Pop Up Test</title>

<link href="htmlStyles.css" rel="stylesheet" type="text/css" />


</head>

<body>
<a class="anc_h41back" href="#"><img class="btnBackArrow_top" src="h41popup_backBtn.png" /></a>


<div id="xslContent"></div>
<div id="xslContent2"></div>
<script>

function getURLVar(urlVarName) {
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		var urlVars = urlHalves[1].split('&');
		for(var i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0].toLowerCase() == urlVarName.toLowerCase()) {
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	
	
	return urlVarValue;
}



function loadXMLDoc(fname){
	var xmlDoc;
	
	// code for IE
	if (window.ActiveXObject){
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument){
		xmlDoc=document.implementation.createDocument("","",null);
	}else{
		alert('Your browser cannot handle this script');
	}
  
	xmlDoc.async=false;
	xmlDoc.load(fname);
	return(xmlDoc);
}

function displayResult(xmlDoc, xslDoc){
	
	var splitXmlDoc = xmlDoc.split('.');
	var newXslDoc = splitXmlDoc[0] + ".xsl";
	
	xml=loadXMLDoc(xmlDoc);
	xsl=loadXMLDoc(newXslDoc);
// code for IE
  if (window.ActiveXObject)
  {
    ex=xml.transformNode(xsl);
    document.getElementById("xslContent").innerHTML = ex;

  }
// code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation
  && document.implementation.createDocument)
  {
    xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
    resultDocument = xsltProcessor.transformToFragment(xml,document);
    document.getElementById("xslContent").appendChild(resultDocument);
	var al = document.getElementById("xslContent").innerHTML;
	
	// this will re-transform the html tags within the CDATA to render correctly in FF
	var rp = al.replace(/&lt;br\/&gt;/g,'<br />');
	
	rp = rp.replace(/&lt;strong&gt;/g,'<strong>');
	rp = rp.replace(/&lt;\/strong&gt;/g,'</strong>');
	
	rp = rp.replace(/&lt;b&gt;/g,'<b>');
	rp = rp.replace(/&lt;\/b&gt;/g,'</b>');
	
	rp = rp.replace(/&lt;ul&gt;/g,'<ul>');
	rp = rp.replace(/&lt;\/ul&gt;/g,'</ul>');
	
	rp = rp.replace(/&lt;ol&gt;/g,'<ol>');
	rp = rp.replace(/&lt;ol&nbsp;type=&quot;a&quot;&gt;/g,'<ol type="a">');
	rp = rp.replace(/&lt;\/ol&gt;/g,'</ol>');
	
	rp = rp.replace(/&lt;li&gt;/g,'<li>');
	rp = rp.replace(/&lt;\/li&gt;/g,'</li>');
	
	rp = rp.replace(/&lt;p&gt;/g,'<p>');
	rp = rp.replace(/&lt;\/p&gt;/g,'</p>');
	
	rp = rp.replace(/&lt;i&gt;/g,'<i>');
	rp = rp.replace(/&lt;\/i&gt;/g,'</i>');
	
	rp = rp.replace(/&lt;br&gt;/g,'<br>');
	rp = rp.replace(/&lt;\/br&gt;/g,'</br>');
	
	
	rp = rp.replace(/&lt;br\/&gt;/g,'<br />');
	
	rp = rp.replace(/&lt;textformat\b(.*?)&gt;/g,'<br/>');
	rp = rp.replace(/&lt;\/textformat&gt;/g,'');

	document.getElementById("xslContent").innerHTML = rp;
  }
}

function displayResult2(xmlDoc, xslDoc){
	
	
	xml=loadXMLDoc(xmlDoc);
	xsl=loadXMLDoc(xslDoc);
// code for IE
  if (window.ActiveXObject)
  {
    ex=xml.transformNode(xsl);
    document.getElementById("xslContent2").innerHTML = ex;

  }
// code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation
  && document.implementation.createDocument)
  {
    xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
    resultDocument = xsltProcessor.transformToFragment(xml,document);
    document.getElementById("xslContent2").appendChild(resultDocument);
	var al = document.getElementById("xslContent2").innerHTML;
	
	// this will re-transform the html tags within the CDATA to render correctly in FF
	var rp = al.replace(/&lt;br\/&gt;/g,'<br />');
	
	rp = rp.replace(/&lt;strong&gt;/g,'<strong>');
	rp = rp.replace(/&lt;\/strong&gt;/g,'</strong>');
	
	rp = rp.replace(/&lt;b&gt;/g,'<b>');
	rp = rp.replace(/&lt;\/b&gt;/g,'</b>');
	
	rp = rp.replace(/&lt;ul&gt;/g,'<ul>');
	rp = rp.replace(/&lt;\/ul&gt;/g,'</ul>');
	
	rp = rp.replace(/&lt;ol&gt;/g,'<ol>');
	rp = rp.replace(/&lt;ol&nbsp;type=&quot;a&quot;&gt;/g,'<ol type="a">');
	rp = rp.replace(/&lt;\/ol&gt;/g,'</ol>');
	
	rp = rp.replace(/&lt;li&gt;/g,'<li>');
	rp = rp.replace(/&lt;\/li&gt;/g,'</li>');
	
	rp = rp.replace(/&lt;p&gt;/g,'<p>');
	rp = rp.replace(/&lt;\/p&gt;/g,'</p>');
	
	rp = rp.replace(/&lt;i&gt;/g,'<i>');
	rp = rp.replace(/&lt;\/i&gt;/g,'</i>');
	
	rp = rp.replace(/&lt;br&gt;/g,'<br>');
	rp = rp.replace(/&lt;\/br&gt;/g,'</br>');
	
	rp = rp.replace(/&lt;blockquote&gt;/g,'<blockquote>');
	rp = rp.replace(/&lt;\/blockquote&gt;/g,'</blockquote>');
	
	rp = rp.replace(/&lt;br\/&gt;/g,'<br />');
	
	rp = rp.replace(/&lt;textformat\b(.*?)&gt;/g,'<br/>');
	rp = rp.replace(/&lt;\/textformat&gt;/g,'');

	document.getElementById("xslContent2").innerHTML = rp;
  }
}

displayResult(getURLVar('sheetFile'),"");
displayResult2(getURLVar('sheetFile'),"h41PrintTransform.xsl");
</script>

<a class="anc_h41back" href="#"><img class="btnBackArrow_bottom" src="h41popup_backBtn.png" /></a>
</body>

</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>H41 Pop Up Test</title>

<link href="htmlStyles.css" rel="stylesheet" type="text/css" />


</head>

<body>
<a class="anc_h41back" href="#"><img class="btnBackArrow_top" src="h41popup_backBtn.png" /></a>


<div id="xslContent"></div>
<div id="xslContent2"></div>
<script>

function getURLVar(urlVarName) {
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		var urlVars = urlHalves[1].split('&');
		for(var i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0].toLowerCase() == urlVarName.toLowerCase()) {
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	
	
	return urlVarValue;
}



function loadXMLDoc(fname){
	var xmlDoc;
	
	// code for IE
	if (window.ActiveXObject){
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument){
		xmlDoc=document.implementation.createDocument("","",null);
	}else{
		alert('Your browser cannot handle this script');
	}
  
	xmlDoc.async=false;
	xmlDoc.load(fname);
	return(xmlDoc);
}

function displayResult(xmlDoc, xslDoc){
	
	var splitXmlDoc = xmlDoc.split('.');
	var newXslDoc = splitXmlDoc[0] + ".xsl";
	
	xml=loadXMLDoc(xmlDoc);
	xsl=loadXMLDoc(newXslDoc);
// code for IE
  if (window.ActiveXObject)
  {
    ex=xml.transformNode(xsl);
    document.getElementById("xslContent").innerHTML = ex;

  }
// code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation
  && document.implementation.createDocument)
  {
    xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
    resultDocument = xsltProcessor.transformToFragment(xml,document);
    document.getElementById("xslContent").appendChild(resultDocument);
	var al = document.getElementById("xslContent").innerHTML;
	
	// this will re-transform the html tags within the CDATA to render correctly in FF
	var rp = al.replace(/&lt;br\/&gt;/g,'<br />');
	
	rp = rp.replace(/&lt;strong&gt;/g,'<strong>');
	rp = rp.replace(/&lt;\/strong&gt;/g,'</strong>');
	
	rp = rp.replace(/&lt;b&gt;/g,'<b>');
	rp = rp.replace(/&lt;\/b&gt;/g,'</b>');
	
	rp = rp.replace(/&lt;ul&gt;/g,'<ul>');
	rp = rp.replace(/&lt;\/ul&gt;/g,'</ul>');
	
	rp = rp.replace(/&lt;ol&gt;/g,'<ol>');
	rp = rp.replace(/&lt;ol&nbsp;type=&quot;a&quot;&gt;/g,'<ol type="a">');
	rp = rp.replace(/&lt;\/ol&gt;/g,'</ol>');
	
	rp = rp.replace(/&lt;li&gt;/g,'<li>');
	rp = rp.replace(/&lt;\/li&gt;/g,'</li>');
	
	rp = rp.replace(/&lt;p&gt;/g,'<p>');
	rp = rp.replace(/&lt;\/p&gt;/g,'</p>');
	
	rp = rp.replace(/&lt;i&gt;/g,'<i>');
	rp = rp.replace(/&lt;\/i&gt;/g,'</i>');
	
	rp = rp.replace(/&lt;br&gt;/g,'<br>');
	rp = rp.replace(/&lt;\/br&gt;/g,'</br>');
	
	
	rp = rp.replace(/&lt;br\/&gt;/g,'<br />');
	
	rp = rp.replace(/&lt;textformat\b(.*?)&gt;/g,'<br/>');
	rp = rp.replace(/&lt;\/textformat&gt;/g,'');

	document.getElementById("xslContent").innerHTML = rp;
  }
}

function displayResult2(xmlDoc, xslDoc){
	
	
	xml=loadXMLDoc(xmlDoc);
	xsl=loadXMLDoc(xslDoc);
// code for IE
  if (window.ActiveXObject)
  {
    ex=xml.transformNode(xsl);
    document.getElementById("xslContent2").innerHTML = ex;

  }
// code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation
  && document.implementation.createDocument)
  {
    xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
    resultDocument = xsltProcessor.transformToFragment(xml,document);
    document.getElementById("xslContent2").appendChild(resultDocument);
	var al = document.getElementById("xslContent2").innerHTML;
	
	// this will re-transform the html tags within the CDATA to render correctly in FF
	var rp = al.replace(/&lt;br\/&gt;/g,'<br />');
	
	rp = rp.replace(/&lt;strong&gt;/g,'<strong>');
	rp = rp.replace(/&lt;\/strong&gt;/g,'</strong>');
	
	rp = rp.replace(/&lt;b&gt;/g,'<b>');
	rp = rp.replace(/&lt;\/b&gt;/g,'</b>');
	
	rp = rp.replace(/&lt;ul&gt;/g,'<ul>');
	rp = rp.replace(/&lt;\/ul&gt;/g,'</ul>');
	
	rp = rp.replace(/&lt;ol&gt;/g,'<ol>');
	rp = rp.replace(/&lt;ol&nbsp;type=&quot;a&quot;&gt;/g,'<ol type="a">');
	rp = rp.replace(/&lt;\/ol&gt;/g,'</ol>');
	
	rp = rp.replace(/&lt;li&gt;/g,'<li>');
	rp = rp.replace(/&lt;\/li&gt;/g,'</li>');
	
	rp = rp.replace(/&lt;p&gt;/g,'<p>');
	rp = rp.replace(/&lt;\/p&gt;/g,'</p>');
	
	rp = rp.replace(/&lt;i&gt;/g,'<i>');
	rp = rp.replace(/&lt;\/i&gt;/g,'</i>');
	
	rp = rp.replace(/&lt;br&gt;/g,'<br>');
	rp = rp.replace(/&lt;\/br&gt;/g,'</br>');
	
	rp = rp.replace(/&lt;blockquote&gt;/g,'<blockquote>');
	rp = rp.replace(/&lt;\/blockquote&gt;/g,'</blockquote>');
	
	rp = rp.replace(/&lt;br\/&gt;/g,'<br />');
	
	rp = rp.replace(/&lt;textformat\b(.*?)&gt;/g,'<br/>');
	rp = rp.replace(/&lt;\/textformat&gt;/g,'');

	document.getElementById("xslContent2").innerHTML = rp;
  }
}

displayResult(getURLVar('sheetFile'),"");
displayResult2(getURLVar('sheetFile'),"h41PrintTransform.xsl");
</script>

</body>

</html>

Open in new window

0
Comment
Question by:toneDigital
  • 3
5 Comments
 
LVL 6

Expert Comment

by:nitinsawhney
ID: 33432086
One thing I would like to point out that your code won't pass validator as javascript nowadays is written as below:

<script type="text/javascript">
// <![CDATA[

// content of your Javascript goes here

// ]]>
</script>

Also, it would be worth checking that all the tags are properly closed as Safari and Chrome follow strict rules.

0
 

Author Comment

by:toneDigital
ID: 33433001
Will look into this. Thanks
0
 

Author Comment

by:toneDigital
ID: 33433416
All is good, all tags are closed, t's crossed and i's dotted but still can't render in Safari or Chrome. Any other suggestions? Thanks
0
 

Accepted Solution

by:
toneDigital earned 0 total points
ID: 33637486
Added the fix to this function and now all is good.


function loadXMLDoc(fname){
	var xmlDoc;
	
	try //Internet Explorer 
    { 
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); 
        xmlDoc.async=false; 
        xmlDoc.load(fname); 
    } 
    catch(e) 
    { 
        try //Firefox, Mozilla, Opera, etc. 
        { 
            xmlDoc=document.implementation.createDocument("","",null); 
            xmlDoc.async=false; 
            xmlDoc.load(fname); 
        } 
        catch(e) 
        { 
            try //Google Chrome 
            { 
                var xmlhttp = new window.XMLHttpRequest(); 
                xmlhttp.open("GET",fname,false); 
                xmlhttp.send(null); 
                xmlDoc = xmlhttp.responseXML.documentElement; 
            } 
            catch(e) 
            { 
            error=e.message; 
            } 
        } 
    } 
    return xmlDoc; 

}

Open in new window

0
 
LVL 9

Expert Comment

by:Sar1973
ID: 37862567
For Mr. ToneDigital: is this a function to be loaded in order to make a generic Javsscript code working with every browser? If so, at which event should it be associated? And loaded also in iframed pages?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question