Load Applet via Javascript function on the same page - javascript

I am trying to load an applet on demand via javascript.
Here is what I've tried:
function startApplet() {
document.write('<applet code="com.pwc.envoyapp.applet.SampleApplet" height=30 width=40 archive="ucfapplet.jar"></applet>');
}
The problem is that it loads the applet in a new page. I need it to open it on the same page so that session keys generated by the applet are preserved.
Is there a way to get the applet to load on the same page?

have you tried something like:
document.getElementById("appletContainer").innerHTML = "<applet ... />";
of course you'd need the element to exist so somewhere in your DOM you'd have:
<div id="appletContainer"></div>
as an empty element waiting to be populated.

Related

Waiting for Web Request Results in HTML <script> Tag

An application I'm writing has the following requirement:
I need to implement a fetch request within a tag, but I need to wait for the results of the request before the rest of the page is loaded? The goal is to run window.stop() if the results match a certain value, but allow the page to fully load if the results don't match the specified value.
Is there any way to implement this?
I know this is not an efficient way to load the page, and it will make the page load slower, but that is not a concern for the current application.
I don't think http requests can be controlled directly through DOMJS, but you can use the following method to do what you want:
The method simply saves the content of the page to a local variable inside the function, and then displays it when you are done with your verification.
This Function Was Be called When Your Browser displayed the basic html content :
function CheckPageContent(){
var appData = document.querySelector("#AppData");
var htmlContent = appData.innerHTML
appData.innerHTML = "";
setTimeout(function(){
appData.innerHTML = htmlContent;
appData.style.display = 'block';
document.querySelector("#Loader").style.display = 'none';
},3000);
}
Your page must be have this structure :
<body>
<div id="AppData" style="display:none">
<img src="https://www.w3schools.com/tags/img_girl.jpg">
<br>
Hello 1Worled!
</div>
<div id="Loader">Loading......</div>
</body>
<script>
CheckPageContent();
</script>
If you want how the method works, then you must first understand how the browser works when you request a page
Until everything is clear, the browser when you request a page, the browser downloads only the hypertext (html) for this page, and then displays it on the page.
In the event that the hypertext contains external files, the browser downloads them separately from the main page.
For example, if the requested page contains this crown
After viewing the basic hypertext, the browser will download the bootstarp file and then normalize it to the already displayed html text .... and so on with the images and other files ....

Javascript From Console - Load a Few Pages, Then Run Function Per Page Load [duplicate]

I'd like to be able to call a jquery function once window.location has completed loading a URL. Is this possible? I can't seem to find anything online about this.
for instance:
if(parseInt(msg.status)==1) {
window.location=msg.txt;
alert("This URL has finished loading")
}
Thanks,
-Paul
You can either use window.onload of the destination page (if you have access to modify the code of that page), or you can use window.onunload to have the alert be launched when unloading the current page. You cannot execute code on the current page after the new page has been loaded.
Yes.
This page demonstrates onload/onunload behavior.
<html>
<head>
<script>
window.doUnload = function(){
alert("Here!");
}
window.doLoad = function(){
window.location="http://www.google.com";
}
</script>
</head>
<body onload="doLoad();" onunload="doUnload();"></body>
</html>
After a user logs in for the first time I need to load my index page to initialize everything but then need to forward them to another page for profile completion.
use window.location to redirect the user to your index, adding a query parameter (something like window.location=index.php?firstLogin=true ) and on your index redirect (using javascipt http 300, header() or whatever you are using) to the profile page after it ends loading if the parameter is set
Iframe
One (ugly) method you could use is to instead of using window.location, clearing the body, adding an iframe with the relevant path and listening to its onload function.
After that you can run code inside the iframe as long as it's not cross-site scripting.
I use this method to perform small automated scripts, that can't really on third-party plugins.
Ajax
Another method might be using ajax to load the page/body content. Then replacing your body with the newly loaded body and start executing the next functions.

How to run JQuery after the main php page include sub php page

I am building my website and in the main PHP page, I got something like this:
...
<a class="aboutMe" href="?section=aboutMe"></a>
<a class="network" href="?section=network"></a>
<a class="map" href="?section=map"></a>
...
If someone click any of the links above, the in the same page, the PHP will do this:
<?php
if(array_key_exists ("section", $_REQUEST)) {
if($_REQUEST["section"] == "aboutMe") {
include(app_path().'/views/about-me.blade.php');
}
else if($_REQUEST["section"] == "network") {
include(app_path().'/views/network/index.php');
}
else if($_REQUEST["section"] == "map") {
include(app_path().'/views/my-trace.php');
}
}
?>
After the sub page is road, it is placed right under the main page, and I would like to make it automatically scroll down to the joint part so the user could see the sub page immediately, something like this:
<main page>
<- scroll to here
<sub page>
It sounds not difficult, and I've already written some jQuery to do this job. However the whole page was refreshed after the including, and the jQuery is run before the fresh. How could I fix that?
Or is that possible to include sub pages without refresh the whole page? This would be a preferred solution. Many thanks in advance!
PHP runs on the server. It sends a response to the user's browser, then javascript runs in the browser. If you want to execute more PHP code after the response has been sent, the user has to send another request to the server and get a new response. You can do this without reloading the page using ajax: http://learn.jquery.com/ajax/
Alternatively, if there are only the three different pages, you could just include the html code for all three pages in the initial response. Then just use javascript to change what is visible.

Add HTML/JS code to external web page after it has loaded

Is it possible to load an external web page like 'http://www.google.com' and then append my own HTML/JS code to the end of it (e.g. to run a function)?? Surely there is a way to load an external page then add a little bit of my own code after it? Something like this:
<html>
<script>
document.location.href="http://www.google.com/"; //Load external page
function myscript() {
...blahblah
}
</script>
<button onclick="myscript();">Click me</button>
</html>
I'd like that button to be at the bottom of the external page. Please do not suggest parsing methods in php. I've tried doing this by parsing the page first in php then appending my own script to it and echoing as I described here:
Append HTML to page after redirect
This works for simple pages where there are no re-directs or when the final external page can be parsed properly. The problem is that I can't properly parse the external page. The code that is parsed doesn't seem to function without the code from previous pages (before the re-directs). I need to do this without parsing/scraping/crawling.
Thanks!
EDIT: I've tried displaying the external page in an iframe as suggested by Amadan:
<script>
function myscript() {
...blahblah
}
</script>
<iframe src="http://www.google.com/"></iframe>
<button onclick="myscript();">Click me</button>
</html>
However, in firefox it just displays a blank box but in IE it says "This content cannot be displayed in a frame: To help protect the security of information you enter into this website, the publisher of this content does not allow it to be displayed in a frame."
Any way I can get around this?
EDIT 2:
I've included jquery and the cross domain script here (https://github.com/padolsey/jquery.fn/blob/master/cross-domain-ajax/jquery.xdomainajax.js). This is the code I'm using now to get the contents using ajax. How would I go from that to actually displaying the content in the webpage? Sorry I'm really bad with ajax/jquery!
function test () {
$.ajax({
url: 'http://www.google.com/',
type: 'GET',
success: function(res) {
var content = $(res.responseText).text();
alert(content);
}
});
}
You can't append anything to a page you don't control except by installing a browser extension (which then works only for the clients where your extension installed).
You can include the contents of a page you don't control inside your own page (in two main ways: client-side iframe and server-side pull), but you seem to be saying this is not what you want.
Try something like this:
var html = '';
$.ajax({
uri: 'http://ya.ru',
method: 'POST',
success: function(data){
htmlx = data;
}
});
About manipulating html inside an variable
var test = $("<div/>");
test.append(html);
test.find(".innertest");
// When I'm ready to append it..
$('#container').append(test);
If it doesn't work, you can use another page on your server for getting a remote page and use ajax to request it.

Is it possible to modify an iframe contents in a classic ASP page after it has loaded

I have a classic ASP page which is loading an ASP.net page through an iframe inside the ASP page. This is working great except for the fact that it takes a while to load the ASP.net page. The user is left here with unfavorable experience because all they say is an empty blank page until the page is finish loading.
What I would like to do is load an initial "loading" ASP.net page so at least the user is shown something and then when the ASP.net page is ready load the correct ASP.net page into the iframe.
Is this possible? I'm thinking perhaps with a bit of javascript but not 100% sure.
There is no "ASP page" once it hits the browser, there is only the resulting HTML.
You have a few problems here:
1) If you put something in the Iframe, it will be over-written as soon as the new page loads. So, you cannot use what's in the Iframe to display your message.
2) How to tell when the Iframe had loaded
You need to determine the location and size of the Iframe on your page. You need to position an element over it with your message. Modify the style of an absolutely-positioned element to cover the Iframe using JavaScript. Most people would use a framework, such as jQuery, to make it a lot easier.
You then need to detect when the Iframe has loaded and hide this element.
You can use this code to determine that the Iframe has loaded:
function checkIframeLoading() {
// Get a handle to the iframe element
var iframe = document.getElementById('testIframe');
// Check if loading is complete
if ( iframe.document.readyState == 'complete' ) {
// The loading is complete, call the function we want executed once the iframe is loaded
functionToCallAfterLoading();
return;
}
// If we are here, it is not loaded. Set things up so we check the status again in 100 milliseconds
window.setTimeout('checkIframeLoading();', 100);
}
You can use JQuery to modify an iframe after the page is loaded.
Another question on stackoverflow already contains a good example:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
var locations = ["http://webPage1.com", "http://webPage2.com"];
var len = array.length;
var iframe = $('#frame');
var i = 0;
setInterval(function () {
$iframe.attr('src', locations[++i % len]);
}, 30000);
});
</script>

Categories

Resources