Solved

Generating HTML with JAVA script to add PARAMETER to Applet

Posted on 2001-06-25
3
363 Views
Last Modified: 2008-02-01
History of problem.

Pass a Parameter to the Applet from server 1 to server 2 without any CGI PROGRAM

For example,

http://ip1/someCGI  ( SERVER 1) program will call

http://ip2/index.html ( SERVER 2) with a parameter to applet names as SESSIONID

So index.html on SERVER2 to be  modified on the fly so that
<PARAM name=SESSIONID value=?12345> if i call the URL

http://ip2/index.html?12345 from SERVER1.



Good Example:

Assume the test.html as follows.

<Script language=JavaScript>
function setParam(){    
     document.writeln("<param name=\"sessionkey\" value=\""+document.location.search+"\">");    
</Script>
<body onLoad="setParam();" >


IF You execute this code in your browser

http://yourip/test.html?12345

the output in the View Source in the IE Browser is

<param name="sessionkey" value="?12345">


CURRENT PROBBLEM:-

So to achieve my problem, Entire .html page to be written in  Java Script as mentioned in the example.
It is the following page. ( It has Swing Enabled Code ).

Name it as index.html

<Script language=JavaScript>
     function setParam(){    
          document.writeln("<HTML><HEAD>");    
          document.writeln("<SCRIPT LANGUAGE=JavaScript><!--");
              document.writeln("var _info = navigator.userAgent; var _ns = false;");
              document.writeln("var _ie = (_info.indexOf(\"MSIE\") > 0 && _info.indexOf(\"Win\") > 0 && _info.indexOf(\"Windows 3.1\") < 0);");
          document.writeln("--></SCRIPT>");

          document.writeln("<SCRIPT LANGUAGE=JavaScript><!--");
              document.writeln("if (_ie == true) document.writeln('<OBJECT classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\" WIDTH = 700  HEIGHT = 500  codebase=\"http://java.sun.com/products/plugin/1.1.2/jinstall-112-win32.cab#Version=1,1,2,0\"><NOEMBED><XMP>');");
              document.writeln("else if (_ns == true) document.writeln('<EMBED type=\"application/x-java-applet;version=1.1.2\" java_CODE = \"App.class\" java_codebase = \"http://101.10.22.171/WEB-INF/classes\" WIDTH = 700  HEIGHT =500   pluginspage=\"http://java.sun.com/products/plugin/1.1.2/plugin-install.html\"><NOEMBED><XMP>');");
          document.writeln("--></SCRIPT>");
          document.writeln("<Applet width=700  height=500  id=Applet1></XMP>");
          document.writeln("<PARAM NAME = CODE VALUE = App.class>");
          document.writeln("<ParaM Name = CODEBASE VALUE = \"http://101.10.12.171/WEB-INF/classes/\">");
          document.writeln("<PARAM NAME = logPort VALUE = 8000 />");
          document.writeln("<PARAM NAME= type VALUE=application/x-java-applet;version=1.1.2>");
          document.writeln("<param name=\"sessionkey\" value=\""+document.location.search+"\">");
          document.writeln("</Applet>");
          document.writeln("</NOEMBED></EMBED></OBJECT>");
          document.writeln("</HEAD>");
     }
</Script>
<body onLoad="setParam();">


I need error free version of above html page.

The errors i am facing:

1.Unterminated String in the line
   A.  document.writeln("var _ie = (_info.indexOf(\"MSIE\") > 0 && _info.indexOf(\"Win\") > 0 && _info.indexOf(\"Windows 3.1\") < 0);");

  B.               document.writeln("else if (_ns == true) document.writeln('<EMBED type=\"application/x-java-applet;version=1.1.2\" java_CODE = \"App.class\" java_codebase = \"http://101.10.22.171/WEB-INF/classes\" WIDTH = 700  HEIGHT =500   pluginspage=\"http://java.sun.com/products/plugin/1.1.2/plugin-install.html\"><NOEMBED><XMP>');");


2. Object expected in the line
<body onLoad="setParam();">

Please fix these three bugs.

NOTE: NO LIVE CONNECT . ONLY SIMPLE  JAVA SCRIPT ...............
Advanced Thanks
0
Comment
Question by:Ravindra76
3 Comments
 
LVL 7

Expert Comment

by:daniel_c
ID: 6224986
How about this?

<html>
<head>
<title>Untitled Document</title>
</head>

<Script language=JavaScript>
    function setParam(){          
         var _info = navigator.userAgent;
         var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0);
         var _ns = !_ie;
         if (_ie == true) {
               document.writeln("<OBJECT classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\" WIDTH = 700  HEIGHT = 500  codebase=\"http://java.sun.com/products/plugin/1.1.2/jinstall-112-win32.cab#Version=1,1,2,0\"><NOEMBED><XMP>");
          }
          else if (_ns == true) {
               document.writeln("<EMBED type=\"application/x-java-applet;version=1.1.2\" java_CODE = \"App.class\" java_codebase = \"http://101.10.22.171/WEB-INF/classes\" WIDTH = 700  HEIGHT =500   pluginspage=\"http://java.sun.com/products/plugin/1.1.2/plugin-install.html\"><NOEMBED><XMP>");
          }
         document.writeln("<Applet width=700  height=500  id=Applet1></XMP>");
         document.writeln("<PARAM NAME = CODE VALUE = App.class>");
         document.writeln("<ParaM Name = CODEBASE VALUE = \"http://101.10.12.171/WEB-INF/classes/\">");
         document.writeln("<PARAM NAME = logPort VALUE = 8000 />");
         document.writeln("<PARAM NAME= type VALUE=application/x-java-applet;version=1.1.2>");
         document.writeln("<param name=\"sessionkey\" value=\"" + document.location.search + "\">");
         document.writeln("</Applet>");
         document.writeln("</NOEMBED></EMBED></OBJECT>");
         document.writeln("</HEAD>");
         return true;
    }
</Script>
<body onLoad="return setParam();">
</body>
</html>

Hope this helps

^_^
0
 
LVL 7

Author Comment

by:Ravindra76
ID: 6225998
Still compilation errors;

Line 8: Unterminated String Constant

Line 32 : Object expected
0
 
LVL 12

Accepted Solution

by:
ahosang earned 300 total points
ID: 6226143
var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows
3.1") < 0);
is probably the unterminated String problem. Make SURE it is all on one line in the source code. If it overflows in your editor, break up the statement in a NON-STRING area, like press return where the '&&' is.

Also this is not the way to write to a document. More like:

<html>
<head>
<title>Untitled Document</title>
</head>

<body>


<Script language=JavaScript>
function setParam(){          
   var _info = navigator.userAgent;
   var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0);
   var _ns = !_ie;
   if (_ie == true) {
     document.writeln("<OBJECT classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\" WIDTH = 700"+
          " HEIGHT = 500  codebase=\"http://java.sun.com/products/plugin/1.1.2/jinstall-112-win32.cab#Version=1,1,2,0\">");
   } else if (_ns == true) {
       document.writeln("<EMBED type=\"application/x-java-applet;"+
           "version=1.1.2\" java_CODE = \"App.class\" java_codebase =\"http://101.10.22.171/WEB-INF/classes\" WIDTH = 700"+
            " HEIGHT =500  pluginspage=\"http://java.sun.com/products/plugin/1.1.2/plugin-install.html\">");
   }
   document.writeln("<Applet width=700  height=500  id=Applet1>");
   document.writeln("<PARAM NAME = CODE VALUE = App.class>");
   document.writeln("<ParaM Name = CODEBASE VALUE = \"http://101.10.12.171/WEB-INF/classes/\">");
   document.writeln("<PARAM NAME = logPort VALUE = 8000 />");
   document.writeln("<PARAM NAME= type VALUE=application/x-java-applet;version=1.1.2>");
   document.writeln("<param name=\"sessionkey\" value=\"" + document.location.search + "\">");
   document.writeln("</Applet>");
   document.writeln("</EMBED></OBJECT>");
   document.writeln("<noembed><xmp>message to browsers that can't use plugins</xmp></noembed>");
}
</Script>

</body>
</html>
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

707 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

16 Experts available now in Live!

Get 1:1 Help Now