Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Netscape Stylesheet problem in Netscape 4.75

    I have a script that will display a person's contact info in a popup window when their name is clicked. The popup window contains a 'Previous' and 'Next' button that when clicked will display the info for the previous or next person in the array of names.

    The problem is that for some reason this line: '<link rel="stylesheet" href="style.css">\n' + is causing the previous and next buttons to not work in Netscape 4.75. If I take out that line it works fine, but I lose the formatting. Am I not writing this line correctly? How can I not lose the formatting?

    Here is the entire code:

    Code:
    <html>
    <head>
    <script language="Javascript">
    <!--
    var employees = [];
    employees[0] = ["James","Smith", "555-1000", "james.smith@spam.net"];
    employees[1] = ["Jean","Smith", "555-2000", "jean.smith@spam.net"];
    employees[2] = ["John","Smith", "555-3000", "john.smith@spam.net"];
    
    var currentEmp = -1;
    function GetNext(xDir) //xDir should be 1 or -1
    { 
    	currentEmp += xDir;
    	if(currentEmp>=employees.length)currentEmp=0;
    	else if(currentEmp<0)currentEmp=employees.length - 1;
    	showEmployee(currentEmp);
    }
    
    var newwin = false;
    function showEmployee(key)
    {
        var emp = employees[key];
        currentEmp = key;
        if(emp)
        {
            if(!newwin  || newwin.closed){
               newwin = window.open('','','top=0,left=0,width=400,height=300');
    	}
    	else
    	{
    		newwin.focus();
    	}
        	var html = 
    		'<html>\n' +
    		'<head>\n' +
    		'<title>' + emp[1].toUpperCase() + ', ' + emp[0].toUpperCase() + '</title>\n' + 
    		'<link rel="stylesheet" href="style.css">\n' +
    		'</head>\n' +
    		'<body>\n' +
    		'<table>\n' + 
    		'<tr><td>' + emp[0] + ' ' + emp[1] + '</td></tr>\n' +  //First
    		'<tr><td>' + emp[2] + '</td></tr>\n' +  //Phone
    		'<tr><td><a href="mailto:' + emp[3] + '">' + emp[3] + '</a></td></tr>\n' +  //Email
    		'</table>\n' + 
    		'<form>\n' +
    		'<input type="button" value="Previous" onclick="window.opener.GetNext(-1);">' +
    		'<input type="button" value="Next" onclick="window.opener.GetNext(1);">\n' +
    		'</form>\n' +
    		'</body>\n' +
    		'</html>';
    	
    		newwin.document.write(html);	
    		newwin.document.close();
    		newwin.focus();
    	}
    	else 
    	{
    		alert('Employee not found.');
    	}
    	return false;
    }
    //-->
    </script>
    
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_reloadPage(init) { //reloads the window if Nav4 resized
    if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
    else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    
    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_showHideLayers() { //v6.0
    var i,p,v,obj,args=MM_showHideLayers.arguments;
    for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
    }
    //-->
    </script>
    </head>
    
    <body>
    
    <table border=0 width=300>
    <tr>
    <td><a href="#" onclick="MM_showHideLayers('A','','show')">A</a></td>
    </tr>
    </table>
    
    <div id="A" class="text" style="position:absolute; left:100px; top:50px; z-index:1; visibility: hidden;">
    <br>A<br>
    <ul type="square">
    <li><a href="#" onclick="return showEmployee(0)">Smith, James</a>
    <li><a href="#" onclick="return showEmployee(1)">Smith, Jean</a>
    <li><a href="#" onclick="return showEmployee(2)">Smith, John</a>
    </ul>
    </div>
    
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try puting each of your lines in the "html" string into an array, and then loop through the array, sorta like so:

    Code:
    with (newwin.document)
    {
    	aHtml    = new Array();
    	aHtml[0] = '<head>';
    	aHtml[1] = '<title>' + emp[1].toUpperCase() + ', ' + emp[0].toUpperCase() + '</title>'; 
    	aHtml[2] = '<link rel="stylesheet" href="style.css">';
    	aHtml[3] = '</head>';
    	
    	for (var i=0; i<aHtml.length; i++) write(aHtml[i]+"\n");
    	close();
    }
    
    newwin.focus();
    not necessarily sure if that will help your problem, but it's a more efficient way of writing to a document, IMHO. one advantage is that you can change the contents of the output easier by simply changing any key of the array.
    *keep it simple (TM)

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by jbot
    Code:
    	for (var i=0; i<aHtml.length; i++) write(aHtml[i]+"\n");
    You don't need to loop to output the contents of the array since the toString method of Array is called automatically when you call the array itself.

    write(aHtml); //the same with write(aHtml.toString());

    Or if you want the newlines after each element:

    write(aHtml.join("\n"));
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •