Solved

multiline document.write or better method

Posted on 2000-03-15
2
354 Views
Last Modified: 2008-03-10
I'm trying to dynamiclly build my web pages for ie and netscape users so that the page is constructed differently for each at the time the page loads, depending on the browser, so far, this is what I'm doing ....

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Browser Check ...</title>
<link rel="stylesheet" href="styles/url.css">
<script language="javascript">
     var uagent;uagent = navigator.userAgent;
     if (uagent.substring(25,29)=="MSIE" && uagent.charAt(30) > 2)
       document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=http://fibdev.com/ie/'>")
     else
       document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=http://fibdev.com/non-ie/'>")
</script>
</head>
</html>

I've tryed to substitute the "document.write" line with html for my ie site code, but I get a syntax error.  I've tryed doing multiple document.write's, but to no avail.  Is there a better way to do this than the approch I'm attempting?
0
Comment
Question by:fibdev
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 50 total points
ID: 2619526
No need for meta tags to redirect:

<script language="javascript">
var ver = navigator.appVersion;
if (ver.indexOf("MSIE") !=-1 && parseInt(ver) > 2)
   window.location='http://fibdev.com/ie/';
else window.location='http://fibdev.com/non-ie/';
</script>

if you want the page to be written, watch the quotes:

<script language="javascript">
var ver = navigator.appVersion;
IE = (ver.indexOf("MSIE") !=-1 && parseInt(ver) > 2)
var text = "";
if (IE) {
   text += '<TIT'+'LE>IE specific page</TIT'+'LE>';
   text += '<BO'+'DY TEXT="#FFFFFF" BACKGROUND="#000000">';
   text += '<H3>Hello and welcome to my IE page </H3>';
   text += '</BO'+'DY>';
}
else {
   text += '<TIT'+'LE>IE specific page</TIT'+'LE>';
   text += '<BO'+'DY TEXT="#FFFFFF" BACKGROUND="#000000">';
   text += '<H3>Hello and welcome to my non-IE page </H3>';
   text += '</BO'+'DY>';
}

document.write(text);
</script>


Michel
0
 
LVL 3

Author Comment

by:fibdev
ID: 2621675
Thanks ...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now