Solved

HTML not rendering in Safari, Chrome

Posted on 2010-08-13
5
1,407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

623 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