I have a site where I am using Java applets and have included deployJava.js load tag in the head area of the page. However when I see resulting HTML in Chrome debugger this script breaks my head content starting body immediately, so other head content appears in body tag!
You can see it live on my site http://viva-games.ru/
Also deployJava inserts an embed tag (right after body opens) so you can see an empty line in the top of page.
What I am doing wrong?
deployJava.js is a pain to integrate since it uses document.write to insert tags in the page before the document is fully loaded. Basically, it doesn't support asynchronous loading.
According to the examples from Oracle, we have to include the file somewhere in the body and call it right after the inclusion. The applet tags will be placed there.
If you want to load it asynchronously using RequireJS for instance or if you want to call it later, after the page is loaded, download the uncompressed version and replace every occurrence of:
document.write(...);
by:
document.getElementsByTagName('body')[0].insertAdjacentHTML('afterbegin', ...);
Then you can call deployJava.runApplet anywhere in your JavaScript. You can even put the applet tags in a div element somewhere in your page. The HTML code:
<body>
...
<div id="appletContainer"></div>
// The include after the div or once the page is loaded
<script type="text/javascript" src="javascript/deployJava.js"></script>
...
</body>
and the file deployJava.js:
document.getElementById('appletContainer').insertAdjacentHTML('afterbegin', ...);
Regarding the empty line, I don't have any explanation but a workaround can be found using CSS. If your applet doesn't show any GUI, you can set the appletContainer's height to 0.
NOTE: Don't hide the appletContainer using display:none, otherwise your applet won't run.
Related
In my application, the http://localhost:8080/TestApplication/subCategories/2 will display subcategories of my table with id 2.
Click Here
When I click on the link rendered by the HTML above, my server is redirecting to http://localhost:8080/SecondOpinion/subCategories/hello
I want it to redirect to
http://localhost:8080/SecondOpinion/hello
How do I achieve that?
First of all, this is nothing to do with "anchor tags". An anchor tag is an HTML element of the form <a name="here">, and it defines a location within the HTML that another URL can link to.
What you have is an ordinary HTML link, and what you are seeing is standard HTML behavior for a relative link.
A relative link is resolved related to the "parent" URL for the page containing the link.
If you want a link to go somewhere else, you can:
Use an absolute URL
Use path in the relative link; e.g. `Click Here
Put a <base href="..."> element into your document's <head> section.
In your case, you seem to be1 combining relative URLs with some unspecified server-side redirection. In this case, you could either:
change as above, so that the URL that is sent to the server (before redirection) goes to a better place, or
change the redirection logic in your server.
I can't tell which would be more appropriate.
1 - I am inferring this because you said "my server is redirecting to". It is possible that you actually mean that the browser is sending that URL to the server, and there is no redirection happening at all.
so i am trying to get an HTML element from a website using Jsoup, but the HTML that i get from the Jsoup.connect(url) is not complete compared to the one that i get using the inspector on the website.
EDIT : this is the link i'm working with https://www.facebook.com/livemap##35.831640894,24.82275312499999,2z
The numbers in the end designate the coordinates of the map, and you don't have to sign in to access the page, so there is no authentication problem
UPDATE :
So i have found that the element that i want does not get expanded using jsoup, is this a problem related to slow page loading ? If so, how can i make sure that Jsoup.connect(url) fully loads the webpage before fetching the HTML
from inspector (the <div id="u_0_e"> is expanded)
from jsoup.connect (the <div id="u_0_e"> is not expanded)
Jsoup dont execute javascript or jQuery events, so you will get a initial page before executing javascript.
I'm using struts2 framework(java/js/html/css combo) for my webapp. I am reading a text file from server and I want to write the response to an iFrame present in the same jsp.
Flow:
(1) On click of a link, I pass the relative URL of the text file to jsp.
(2) When the jsp page loads, the java code in the jsp reads the file from server.
(3) Now this response has to be written to an iFrame present in the same jsp file
Can anyone plz help me in writing such response to an iFrame?
Thanks in advance :)
[code not tested, only a demostration of the concept]
here's some very rough idea as to how to fix your code, they definitly not the best but they should be enough to help you understand the concept.
However I'd still recommend going over the whole concept and maybe come up with a more efficent way to do what you need.
if you insist on using iframe, you need to make use of 2 seperate jsp as W3C says in "Implementing HTML Frames":
Any frame that attempts to assign as its SRC a URL used by any of its ancestors is treated as if it has no SRC URL at all (basically a blank frame).
so you'll need 2 jsp, the first one is basically what you have but the the src of the iframe changed to:
<iframe scrolling="yes" width="80%" height="200" src="second.jsp?content=<%=all%>" name="imgbox" id="imgbox">
and the second one will be something like :
<html><body><%= request.getAttribute("content") %></body></html>
From the code you've shown you forced a "content update" on the iframe by using javascript. The proper/usual way to update an iframe is to provide different input parameter to the second jsp and let it update it for you.
Finally, I'd recommend using JSTL as much as possible instead of scriptlets. It is much cleaner.
What you need to do is set the src attribute of the IFRAME to the jsp url when your link is clicked. Another way to do it is doing something like this:
<iframe src="" name="iframe_a"></iframe>
<p>W3Schools.com</p>
with the correct parameters of course
I am looking at writing a tutorial for a Java concept where it would be really nice if I could write the tutorial as a HTML-document with pretty printed Java sources.
I understand I can do this with e.g. http://code.google.com/p/google-code-prettify/ if I copy the various Java sources in my HTML document where I want them to be and put a styling class on the surrounding tag.
However, in order to ensure that the snippets are up to date I would really like to have the HTML page refer to the actual, real Java source files instead of a manually maintained copy.
To my understanding - which may be wrong - this is not supported directly by the Google Prettyprint library, but perhaps some trickery with Javascript pulling in the file and putting it in the DOM tree inside a <pre> tag could do it? I would like the HTML file to be present in the local file system, so doing server side scripting is not an option.
My question is - how can I do this?
(I intend to have the HTML file physically placed at the root of the source tree. This mean that all references from HTML to Java sources will be relative and without '..'. I do not know if that is important or not.)
There is no way to access files directly using JavaScript. JavaScript is restricted in this way for obvious security reasons.
You will need your webserver to serve the Java files. You don't need to do server side scripting but the content of your Java files has to be available at some web address. If they are you can load the content of the Java files with AJAX and inset the content into your webpage.
Using jQuery loading the text could be done as follows
$.get('java/somefile.java', function(data) {
$('#sourceCodeDestination').html(data);
// Prettyprint neeeds to run again in order to see the newly added code
prettyPrint();
}, "text");
This will load the url java/somefile.java get the content of it as plain text and insert it into the DOM element with the id sourceCodeDestination. For more information see the jQuery documentation on get() and ajax().
Here is a demo. As you can see it loads a minified version of the Prettyprint sourcecode from a CDN and pretty prints it.
if your users can accept the requirement of online access while reading your document, you could host your code somewhere like gist (https://gist.github.com/), and embed it in your html dopcument (see example by putting this into your document <script src="https://gist.github.com/sangohan/6494440.js"></script>)
Assuming prettify.js has been loaded previously you can invoke the function prettyPrint which takes arguments callback and rootNode.
<div id="foo">
<pre id="bar"></pre>
</div>
var pre = document.getElementById('bar');
pre.textContent = 'function () {\n return;\n}'; // assign code
pre.className = 'prettyprint'; // assign class
prettyPrint(null, document.getElementById('foo')); // prettify
DEMO
how to get html source code which was rendered by a javascript in webpage. How can i proceed this? Using xsl or javascript or java.
Get entire HTML in current page:
function getHTML(){
var D=document,h=D.getElementsByTagName('html')[0],e;
if(h.outerHTML)return h.outerHTML;
e=D.createElement('div');
e.appendChild(h.cloneNode(true));
return e.innerHTML;
}
outerHTML is non-standard property thus might not supported in some browser (i.e., Firefox), in this case this function mimic the outerHTML feature by cloning the html node into unattached element and read it's innerHTML property.
Javascript provides
document.getElementByTagName('')
You can get any tag from this line. Moreover if you want to do any operation to this tag then assign any id to that tag. then you can use document.getElementById('') to do any operation on it.
These will give you source code.