I want to add progress bar when the applet is loaded on all browsers (Google Chrome, Mozilla Firefox , Internet Explorer , Safari, Opera) . I try to make this with javascript and html body onload method. I use below code..
<html>
<head>
<title>Your Title Here</title>
</head>
<script src="/jquery.js" type="text/javascript">
</script>
<script src="/jquery.browser.js" type="text/javascript">
</script>
<script language="JavaScript" type="text/javascript">
//if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
//alert("firefox");
//}
function init() {
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
var isFirefox = typeof InstallTrigger !== 'undefined';
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor')>0;
var isChrome = !!window.chrome && !isOpera;
var isIE = /*#cc_on!#*/false || document.documentMode;
if(isIE == 11)
{
if(document.applets[0].visibility="visible")
{
alert("Loading On Internet Explorer");
document.all.loading.style.visibility="hidden";
}
}
if(isChrome == true)
{
//alert("Google Chrome");
if(document.applets[0].visibility="visible")
{
alert("Loading On Google Chrome");
document.all.loading.style.visibility="hidden";
//alert("Loading On Google Chrome");
//alert("internet explorer");
//alert("Loading...");
//document.writeln( "User Agent = " + navigator.userAgent );
//document.loading.visibility="hidden";
//document.all.loading.style.visibility="hidden";
}
}
if(isFirefox == true)
{
//alert("mozilla firefox");
if(document.applets[0].visibility="visible")
{
alert("Loading On Mozilla Firefox");
document.all.loading.style.visibility="hidden";
//alert("internet explorer");
//alert("Loading...");
//document.writeln( "User Agent = " + navigator.userAgent );
//document.loading.visibility="hidden";
//document.all.loading.style.visibility="hidden";
}
}
if(isSafari == true)
{
//alert("Safari");
if(document.applets[0].visibility="visible")
{
alert("Loading On Safari");
//alert("internet explorer");
//alert("Loading...");
//document.writeln( "User Agent = " + navigator.userAgent );
//document.loading.visibility="hidden";
//document.all.loading.style.visibility="hidden";
}
}
}
</script>
<style type="text/css">
#loading {
position:absolute;
left:150;
top:200;
}
#myapplet {
position:absolute;
left:10;
top:10;
visibility:hide;
}
</style>
<body onLoad="init()">
<div id="loading">
<p>Loading applet, please wait.</p>
</div>
<applet archive="app1.jar" code="app1.class" align="baseline" width="620" height="442">
<p>Requires a browser that supports Java.</p>
</applet>
</div>
</body>
</html>
Above code works true on internet explorer but not work true on firefox and chromium. Progress Bar disappear when install plugin pop up message is shown in mozilla firefox before applet fully loaded. This progress bar must disappear after applet fully loaded. How can i do this with mozilla firefox and google chromium correctly. Should i use different codes for each browsers..
"I want to add progress bar when the applet is loaded on all browsers". With using javascript and html u can't understand applet is loaded on browsers. You are dealing unnecessary things. I suggest you to read this discussion.How To Show Progress Bar When The Java Applet Load On Web Browser
Related
I'm having a JSP page as follows :
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Admin Tools</title>
<jsp:include page="/basic/nav.jsp"/>
<link rel="stylesheet" type="text/css" href="tools.css"/>
</head>
<body>
<div class="container">
<h2>Admin Tools</h2>
<br/><br/><br/><br/>
<%#page import="java.sql.ResultSet"%>
<%
boolean def_admin = false, def_admin_changed = false;
conn.connect.main(null);
conn.dbc.main(null);
ResultSet rstools = conn.connect.st.executeQuery("select * from admins where uname='admin'");
if (rstools.next()) {
if (rstools.getString("uname").equals("admin") && rstools.getString("password").equals("123")) {
def_admin = true;
}
if (rstools.getString("uname").equals("admin") && !rstools.getString("password").equals("123")) {
def_admin_changed = true;
}
}
%>
<%if (def_admin == false) {%>
Add Default Admin Account :<br/>
<input type="button" value="Add" onclick="<% add_admin(); %>"/>
<% } else if (def_admin == true && def_admin_changed == false) { %>
Delete Default Admin Account :<br/>
<input type="button" value="Delete" onclick="<% delete_admin(); %>"/>
<% } else if (def_admin == true && def_admin_changed == false) { %>
The Default Admin Password Exists but the password has been changed<br/>
Do you still want to delete the Default Admin Account?<br/>
<input type="button" value="Even so, Delete it" onclick="<% delete_admin(); %>"/>
<% }%>
<div id="tools_error"></div>
<%!
boolean insert_success = false;
void add_admin() {
try {
int Urows;
Urows = conn.connect.st.executeUpdate("insert into admins(uname,password) values('admin','123');");
if (Urows == 1) {
insert_success = true;
} else {
insert_success = false;
}
%>
<script>
(function () {
boolean i_s = "<%=insert_success%>";
if (i_s == false) {
document.getElementById("tools_error").value = "There has been an error in Adding Default Admin";
}
});
</script>
<%!
} catch (Exception e) {
}
}
void delete_admin() {
}
%>
</div>
</body>
<jsp:include page="/basic/footer.jsp"/>
</html>
As you can see when the button is clicked I have made it to run the declared JSP functions. But when the JSP file is loaded the functions run automatically and the insert MYSQL query runs which automatically inserts the values given in the query.
I don't want it the functions add_admin() and delete_admin() to run automatically on load. Any suggestions?
The events in the webpage (onclick event for example) is executed client side when someone opens your webpage and clicks the button. The JSP scriplets are executed when the webpage is opened and their result is the actual page that the client receives. So your method executes ONLY when the page is loaded (and the JSP is compiled). The java code is not even visible in the webpage you generate. If you open it in browser and check the source you will see what I mean.
TL;DR: You can't
Your Java code is executed once, when the page is loaded. The page is not on the server anymore, so you can't use its back-end capabilities. Otherwise, that would mean someone reewriting your HTML could make your page execute any code on your back-end.
Once your page is loaded, all there is on it is HTML and Javascript (CSS if you want to bicker).
I have a script thats using papa parse to check for an entry in a CSV file, then redirecting based on if its there or not. It works perfectly fine in chrome on my desktop, has a few issues on firefox on my desktop, and completly doesnt work on my chrome browser on my android.
<body>
<form id="usrform">
<td><label>Unique ID</label></td>
<tr>
<td colspan="2"><input class="textBox" id="uniqueID" type="text" maxlength="30" required/></td>
</tr>
</form>
<button onclick="processClick()">Proceed</button>
</body>
<!-- Jquery import -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<!-- Papa Parse CSV -->
<script src="http://localhost/client/js/papaparse.min.js"></script>
<div id="loading" style="background:url(/images/loading.gif) no-repeat center center;width:20px;height:20px; visibility:hidden">
<img src="/images/loading.gif">
</div>
<script>
// hide loading icon
document.getElementById("loading").style.visibility = "hidden";
function processClick()
{
document.getElementById("loading").style.visibility = "visible";
if (document.getElementById("uniqueID").value == '' )
{
alert("Please fill in the uniqueID field");
document.getElementById("loading").style.visibility = "hidden";
}
else
{
parseData(**client site**/csv/csv.csv", searchArray);
}
}
function parseData(url, callBack) {
Papa.parse(url, {
download: true,
dynamicTyping: true,
complete: function(results) {
alert("parsed ready to callback");
//callBack(results.data);
}
});
}
function searchArray(data) {
//Data is usable here
console.log(" searching array");
for (a = 0; a < data.length; a++)
{
if (data[a][1] == document.getElementById('uniqueID').value)
{
// redirect
var target = "**clientsite**" + document.getElementById('uniqueID').value + ".html";
window.location.assign(target);
break;
}
else
{
console.log(" redirecting on fail");
// redirect to failure page
}
}
}
</script>
I used alerts to see where it stopped working on mobile, and it appears that the function parseData(url, callBack) { is not returning a value(whether its processing or not i cannot tell).
This works perfectly on chrome/desktop, which is the confusing part!
I imagine im missing something stupid here.
There was my error i didnt catch when uploading from testing on my local server. It was working as it could see my localhost file, but it wouldnt for anyone else!
HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-15" />
<script type="text/javascript">
var foo;
function test(s)
{
foo = s;
alert(foo);
}
window.onload = function ()
{
foo = 'init';
document.getElementById('foo').doit();
alert(foo);
}
</script>
<body>
<applet id="foo" code="TestApplet.class"
archive="TestApplet.jar" width="0" height="0"></applet>
</body></html>
Java applet code:
public void doit ()
{
try {
getAppletContext().showDocument(
new URL("javascript:test(\"foobar\")"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
When I call this HTML page :
In IE (8) I get: First popup ("foobar"), second popup ("foobar").
In Firefox (19.2, 30.0) I get: First popup ("foobar"), second popup ("init").
Can anybody explain why? Obviously, foo is written by the applet only temporarily.
Many thanks in advance.
I am trying to develop application in phone gap.It monitors server jobs. Currently server is not available so I made my system as server. I put project files in the same directory where my server is installed. I am trying to access my files in main activity. But it is showing error on my emulator. Error heading is Protocol not Supported. I am sharing main activity file and html file below. Please look at these files.
Main Activity File:
package com.example.productionmonitor;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends DroidGap{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("Here");
super.setIntegerProperty("loadUrlTimeoutValue",120000);
super.loadUrl("file////C:/Program Files/Elixir Technologies/Tango/tomcat/webapps/productionmanagerserver/Monitor app/productionMonitor.htm");
//super.loadUrl("file:///android_asset/www/productionMonitor.htm");
//super.loadUrl("C:///|\Program Files\/Elixir Technologies\/Tango\tomcat\webapps\productionmanagerserver\Monitor app\productionMonitor.htm");
//super.loadUrl("http:///localhost:8080/productionmanagerserver/productionMonitor.htm");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
This is that html file which I saved in location(C:\Program Files\Elixir Technologies\Tango\tomcat\webapps\productionmanagerserver\Monitor app\login.html) and I want to access this file.
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Varela+Round">
<link rel="stylesheet" href="./files/login.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script>
var strFile ;
function userLogin()
{
window.location.href = "productionMonitor.htm";
}
function init()
{
var xmlhttp = null ;
try {
xmlhttp = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
xmlhttp = new ActiveXObject("MsXML2.XMLHTTP");
} catch (othermicrosoft) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
xmlhttp = null;
}
}
}
if (xmlhttp == null)
alert("Error creating request object!");
if ("withCredentials" in xmlhttp) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
//xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xmlhttp = new XDomainRequest();
}
return xmlhttp ;
}
function CallWebservice()
{
var req = init() ;
var url ="http://localhost:8080/identityserver/domains/allData";
req.open('GET',url,true);
req.send(null);
req.onreadystatechange = function() {
if (req.readyState != 4) return; // Not there yet
if (req.status != 200) {
// Handle request failure here...
alert("Call failed");
return;
}
// Request successful, read the response
strFile = req.responseText ;
parseDomainList(strFile);
}
}
function parseDomainList(dlist)
{
var xmlDoc = new DOMParser().parseFromString(strFile,'text/xml');
var domain = xmlDoc.getElementsByTagName("domain");
for (i=0;i<domain.length;i++)
{
var dname =domain[i].getElementsByTagName("domain_name");
var domainid = document.getElementById("domain") ;
var option=document.createElement("option");
domainid.appendChild(option);
}
alert(strFile) ;
userLogin() ;
}
</script>
</head>
<body>
<div id="login">
<h2><span class="fontawesome-lock"></span>Sign In</h2>
<form action="javascript:void(0);" method="POST">
<fieldset>
<p><label for="email">User Name</label></p>
<p><input type="email" id="email" value="admin" onBlur="if(this.value=='')this.value='admin'" onFocus="if(admin')this.value=''"></p>
<p><label for="password">Password</label></p>
<p><input type="password" id="password" value="admin" onBlur="if(this.value=='')this.value='admin'" onFocus="if(this.value=='admin')this.value=''"></p>
<p><label for="domain">Domain List</label></p>
<p><select type="domain" id="domain"> </select> </p>
<p><input type="submit" value="Sign In" onclick="CallWebservice()"></p>
</fieldset>
</form>
</div> <!-- end login -->
</body>
</html>
It really doesn't matter where you put the files on your windows machine. Neither your android device, nor the Emulator can never access them. That'd be scary, if you think about it.
You'll need to turn your development machine into a proper server and then access it with the special ip address 10.0.2.2 from the emulator, which is the development machine's loopback. If you're testing on a device, you'll need to access the development machine's local IP address, presuming you're on the same LAN.
I have a web page with an applet as the only element that looks something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>...</title>
</head>
<body>
<applet style="padding:1px; border:1px solid gray" mayscript="mayscript" codebase="..." name="AppletName" code="..." archive="..." width="600" height="500" alt="Alt Text">
<param name="initial_focus" value="true"/>
Alt Text
</applet>
</body>
</html>
When the page initially loads, focus is set in the applet and I can tab through and interact with the applet just fine. However, if I leave the browser window and then come back to it, I can no longer regain focus on the applet just using the tab key.
Pressing F5 to reload the page fixes the page so that the Applet regains focus, but this solution is unacceptable.
How do I solve this problem? Thanks.
Tentative solution:
//Dean Edwards/Matthias Miller/John Resig
function init() {
// quit if this function has already been called
if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
arguments.callee.done = true;
// kill the timer
if (_timer) clearInterval(_timer);
window.onfocus = function() {
if(!document.AppletName.isActive())
document.AppletName.requestFocus();
};
}
/* for Mozilla/Opera9 */
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, false);
}
/* for Internet Explorer */
/*#cc_on #*/
/*#if (#_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete") {
init(); // call the onload handler
}
};
/*#end #*/
/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
var _timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
init(); // call the onload handler
}
}, 10);
}
/* for other browsers */
window.onload = init;
Note that the key part for detecting whether the applet needs focus and requesting it if so is (this only works if mayscript is enabled):
if(!document.AppletName.isActive())
document.AppletName.requestFocus();
The rest of the code is just attaching the window on focus handling after the page is loaded (using the script JQuery.ready is based off of).
Better solutions welcome.