How do i share javascript with JSP pages without losing context? - javascript

I´m building a application that takes a picture from the webcam in certain interval of time. Basically i'm calling a js function that takes the snapshot time to time,the js is triggered by a click event in a jsp page, to start the function.
Can i keep the js running when i´m switching between jsp pages? Is that possible?

A page reload resets the state.
Given the limited problem description, I would say use Ajax - define a button onclick event, in which take the picture then submit it via Ajax.
If you use a form-based upload, you can submit a form without reloading the page.
If this doesn't suffice have a look at How to upload photos using web app.

Related

Java HtmlUnit background JavaScript loading

I have a website I'm trying to navigate using HtmlUnit.
This website changes certain buttons/makes certain elements visible/hidden based on JavaScript events.
The simplest example I can give: there is a text input box and a button with a class on it that prevents it from being clicked. As soon as text is written in the box the button becomes clickable. I am setting the value of the input text box but am not seeing the updates on the button.
I have tried the following in order to make the page wait for background updates:
use NicelyResynchronizingAjaxController() as the web client's ajax controller
override processSynchron() to return true when setting ajax controller
putting the thread to sleep a few seconds
synchronising on the page variable and calling wait on it for a few seconds
calling waitForBackgroundJavaScript on the web client
looping while the page's enclosing window's job manager has no more JavaScript jobs
Looks like you are using a really low level method.
Try
using the type("...") method
then waitForBackgroundJavaScript() to wait for the javascript to process
If this does not help you have to provide a detailed sample to give us a chance to see your code and do some analysis/debugging.

Click a button on a page to increment a counter in another page using PHP?

so as the title says, I've a button on my main page which should send the amount of times clicked to another page.
I know how to do this via JS, but not in PHP. PHP is also not live, so I'd need to refresh the webpage in order to see the effect, I've been reading about it and I might try and mess around with AJAX to refresh a certain element of my webpage.
Is it possible to do this?
I think you should save it somewhere because PHP is handled server side. So either a cookie/session or a database.

Refreshing a HTML page with Java

I'm working on an Automation project using TestNG. I have created a Listener that updates a HTML file every time there is a test passed/failed/skip etc.
The only issue I have is that if I want to see these changes I have to manually refresh the HTML page.
Is there any code I can use within Java to automatically refresh a HTML page whenever a change is made to it or just refresh every second once the program is running?
EDIT: Seen that its mostly javascript this is done through so some advice on how to integrate JS into my Java class would be beneficial also, thanks.

Safely reset (including running js) complete page to just like blank page

We provide live chat service to our customers. customer just copy some code and put in their footer. then they can have video chat, cobrowsing and many things..
but problem comes when user switch from page to page. so we have resume functionality as well. but thats not robost solution.
So i've come to two solution.
1. Iframe solution
i'll give client a some.html file which he'll need to upload to their root url, then upon video chat and cobrowse we load that page in some.html's iframe and chat appear in some.html
so that work well. chat box apprear seamlessly no page reload effects came in. and as its on same domain i can access all contents of iframe.
2. Another hack solution (not implemented yet, looks good solution)
i was thinking that instead of redirecting user to new page (some.html)
i should clear all contents of current page and load same url in one iframe within the page.
i think that will work well. but i affraid that some client might be using complex js based web app. so if i remove complete body from their page they might have problems.
as much as i know i can remove all dom nodes with their events handlers as well. but is their way to clean js runtime. so all js objects will destroyed and removed from scope so no longer run.
so is there a ways to clear any page completely with all its html and associated java-script as well. means reset page to blank.
Finally i found that there is no way to reset page.. but got another way to make it done.
upon need we can redirect user to same page with query string that identity that its reload for iframe, we put small bit of another code at head which remove all dom before loading dom, css, js.. and create just one iframe of same url.
thus it allows me, have user see no change in url, user browse website as normal without any problem and my chatbox always be there in same state across all pages.
will make it live soon on tagove.com
Why don't you empty the HTML page using empty() function of jquery first,
Then remove/update the link i.e.<script src="...."></script> so that the HTML has no dependency on that javascript and that way it won't be able to Modify the DOM.
And then try to build a javascript program to remove any file in the folder which is isolated(No calling, No dependency, no connection whatsoever)

Reloading a page using jQuery while retaining some data

Are there any clever ways of resetting a page back to it's original state (basically a reload) without having the screen physically look like it resets.
Basically i have a bunch of ajax requests, variables and content that i want wiped when a user clicks 'new' (currently i'm using just using location.reload(); ) but want a more graceful way of doing it.
I'm really wanting to refresh it without the screen going white for a split second and also want to retain a single modal popup i have which is open when the user clicks 'new'.
So the user clicks the 'new' button, a popup appears taking a parameter, the site refreshes and the parameter is passed to an Ajax request kicking off the start process.
If anyone could point me in the direction of what to even look for it'd be much appreciated.
"Are there any clever ways of resetting a page back to it's original state (basically a reload) without having the screen physically look like it resets."
You can't refresh the website without making it look like it refreshed, the browser needs time to display the content.
You can, however, use jQuery .load to load some standard markup into your site to make it appear as it did when it was initialized, the browser won't refresh, just like making an AJAX call doesn't require the website to refresh.
I'm, however, unable to see why you want the website to refresh if only to make an AJAX call.
The simple answer is to have the content you want to reload inside a container i.e.:
<div id="container"> page content </div>
Then when you have successfully got new data from the ajax call you can empty the container with:
$("#container").empty();
and repopulate it with
$("#container").append(newcontent);
You can use jQuery's .load to request and replace a portion of your page, e.g. a container element.
For example, calling the following on index.html would effectively "reset" the #container element:
$("#container").load("index.html #container");
See "Loading Page Fragments" on the docs for $.load.
As for resetting variables and cancelling any pending ajax requests - you could perhaps write a reset() function to do all that for you.
Another possibility would be to put data in local storage, or in the url after a # before the reload. But your options for having it look like it isn't refreshing are pretty limited outside of jQuery .load or an XHR request (which is what the jQuery load does)

Categories

Resources