call Javascript function from OUTSIDE the browser? - javascript

I have a Windows tray application that needs to communicate with my web-application, especially displaying incoming call information.
The telephony-application (ProCall) can start applications when a call-event is received.
I could open a specific URL in a new browser window, but ideally I would like to start a Javascript function of an EXISTING browserwindow and then do it with AJAX.
Is this even possible?

You could have your application talking to a local service via AJAX (with polling) or COMET and have the tray application either host that service or talk to that service. That way you could have a pretty easy channel of communication from your browser to the tray application.
Otherwise you're looking at something like an active x control as far as I know.

You can insert <script> tag on the page?
If yes you can put inside function call, or other code

if you can change the javascript source, i'd say that the url you call have aditional GET/query string parameters, or a hash, and that your js parses it and act accordingly
if you want to use an existing window, you can probably get the instance using COM and with some method around change the hash of one of the open websites to send commands to javascript without reloading. i'm pretty sure it is possible to do something like that with IE, and probably with FF. of course, you need to create a desktop app that get the instances and call its methods. i'd recommend .net or a .vbs script

You want communication between two browser windows, but first you must start from the first step: How will you relate a browser window to another one?
Why should A contact B not C?
The answer depends on this relationship. For example, if A is somehow causing B to spawn, it would be a matter of passing a "pointer" to B (which could simply be a session ID).

Related

can local storage store the whole page

so I have seen a lot of people using local storage to store certain parts of a web page but not an entire web page is it possible? , if so how? , if not is there a way to store an entire web pages data so the user can come back to it how they left it?
This can be done if you use javascript to save document.body.innerHTML into the webstorage and you use javascript to load it back from the storage when the page is loaded next time. If the web page is not in the webstorage, you could redirect the user to the web page.
But this depends on the design of your web page and if there is session index etc in the body of the web page.
You should also think of some way to handle versions. You dont want your users only use the cached version of your web page, but it should be updated once you update your web page.
The session storage is ~5mbit, so you cant save very much, especially not pictures.
Since LocalStorage allows you to store about 5MB~ you can store a full webpage there and then just call it into a document.write().
The following code does it:
Storing it:
var HTML = ""; //html of the page goes here
localStorage.setItem("content", HTML);
Retrieving it:
document.write(localStorage['content']);
Although this is possible it is common practice you only save settings and load them up into the right elements rather than the entire web page.
This is not really answering your question, but, if you are only curious how this can be done and don't need to have wide browser support, I suggest you look into Service Workers, as making websites offline is something that they solve very well.
One of their many capabilities is that they can act as a proxy for any request your website makes, and respond with locally saved data, instead of going to the server.
This allows you to write your application code exactly the same way as you would normally, with the exception of initializing the ServiceWorker (this is done only once)
https://developers.google.com/web/fundamentals/getting-started/primers/service-workers
https://jakearchibald.github.io/isserviceworkerready/
Local storage it's actually just an endpoint: has an IP address and can be accessed from the web.
First of all, you need to make sure that you're DNS service points on your Index page.
For example, if your Local-storage's ip is 10.10.10.10 and the files on that local-storage is organized like:
contants:
pages:
index.html
page2.html
images:
welcome.png
So you can point your DNS like:
10.10.10.10/index -> /contants/pages/index.html
In most of the web frameworks (web framework it's a library that provide built in tools that enable you to build your web site with more functionality and more easily) their is a built in module called 'route' that provide more functionality like this.
In that way, from you index.html file you can import the entire web site, for example:
and in your routes you define for example:
For all the files with the .html extension, route to -> 10.10.10.10/contants/pages/
For all the files with the .png/.jpg extension, route to -> 10.10.10.10/contants/images/
Local storage is usually for storing key and value pairs, storing a whole page will be a ridiculous idea. Try instead a Ajax call which Returns an partial view. Use that for the purpose of manipulation in DOM

Handling browser refresh button in extjs

I am developing a Extjs 5.0 desktop web application. In first page i am storeing text value in singleton class using config methods and In the second page i am displaying same singleton class values using get methods. this works fine.
But if the user clicks browser refresh button on the second page all singleton values are resetting to null. how to solve this issue. How to handle browser refresh button, I have to have use the singleton class to store the values.
Thanks.
The issue is that JavaScript is client side so it has to get made when the page is loaded. The safest solution to your problem would be to store using a backend like PHP. You could put it in a database or in a regular file.
If using a backend isn't possible/desirable then your only solution is to use cookies/localStorage. Both are limited and both are volatile (if the user deletes their cookies the data is gone). Also neither of those solutions are secure if that is a concern for you.

Session null after window.open in minimal SharePoint page

I'm storing a token in a session variable. I launch a report that needs this token in a new ASPX page by using the javascript windows.open function. When this new page loads the HttpContext.Current.Session is null.
I have gotten around this by passing the token in the query string but activity in this window needs to keep the session of the parent window active and I'm not sure what the session object being null means for this scenario.
Any idea why the HttpContext.Current.Session object would be null by using window.open from javascript?
EDIT: I will add that this is a basic System.Web.UI.Page stored in a SharePoint library and the window.open function is called from a webpart. I'm thinking that this page may need to inherit from a base class to share the right context.
UPDATE: I've narrowed down that this is related to SharePoint. I moved the code that accesses the Session object into a web part. The web part works fine if put in a standard web part page but I have it added to a minimal page that only contains a ScriptManager, SPWebPartManager and a WebPartZone. The code runs but the session object is again null. My minimal page is missing something that makes the Session object available.
SOLVED: My minimal ASPX page needed to implement the IRequiresSessionState interface. After that the Session object is there.
I'm going to give the cred to Andrey since he offered the most useful information.
Technically, it's a different connection to the web site, that's why it's a different session. It's probably better to use Application cache instead of session if you want different windows to utilize the same session storage.
UPDATE:
What you can do if you want to stick to using session state, is to write the session ID to a persistent cookie, this way the child window's call to the server will carry it along and you can retrieve SessionID from that cookie. IMPORTANT: Make sure you encrypt session ID ebfore putting into teh cookie to avoid session hijacking.
window.open() should keep the same session id
window.open() clears session
make sure that the url you pass to the open() method is relative or the same domain name
I assume you are using IIS 6 or later.
Lets say you have 2 different websites:
http://site1.yourdomain.com
http://site2.yourdomain.com
2 things can happen
Both sites run under the same Application Pool: Session should be the same for both sites.
note: Internet Explorer prior to version 8 gets assigned different session if the newest window is not originated from the currently open window. Starting on version 8 all windows accessing the same Application Pool share the same version regardless the origin of the window.
Sites run under different Application Pools in IIS: Not even dreaming you can share the same session for both windows
If the website is the same for both windows you shouldn't have any problem sharing session between two windows, even with any version of Internet Explorer since the second window is originating from the first one by calling window.open() method.

How can I scrape an ASP.NET site that does all interaction as postbacks?

Using Python, I built a scraper for an ASP.NET site (specifically a Jenzabar course searching portlet) that would create a new session, load the first search page, then simulate a search by posting back the required fields. However, something changed, and I can't figure out what, and now I get HTTP 500 responses to everything. There are no new fields in the browser's POST data that I can see.
I would ideally like to figure out how to fix my own scraper, but that is probably difficult to ask about on StackOverflow without including a ton of specific context, so I was wondering if there was a way to treat the page as a black box and just fire click events on the postback links I want, then get the HTML of the result.
I saw some answers on here about scraping with JavaScript, but they mostly seem to focus on waiting for javascript to load and then returning a normalized representation of the page. I want to simulate the browser actually clicking on the links and following the same path to execute the request.
Without knowing any specifics, my hunch is that you are using a hardcoded session id and the web server's app domain recycled and created new encryption/decryption keys, rendering your hardcoded session id (which was encrypted by the old keys) useless.
You could try using Firebugs NET tab to monitor all requests, browse around manually and then diff the requests that you generate with ones that your screen scraper is generating.
If you are just trying to simulate load, you might want to check out something like selenium, which runs through a browser and handles postbacks like a browser does.

JavaScript object oncreate event like in win32 api programming - is it possible

I want to monitor object creation.
For example, I want to dynamically change some https links to http using JavaScript.
I can do it in the page onload event by fetching all object anchors and can replace the href,
but I want to do that at the instance of the object creation instead of waiting till the page has loaded. So to prevent users from clicking any link which had already appeared at the top of the page and if the page is taking some time to load then the URL would have had replaced to my desired path. so that is the reason I want to change the href to a different URL or replace https to http.
I haven't heard or read about on create event so I am posting it here. People should have alternatives or other options which we have not yet heard, read or used.
Are you sure JavaScript is the right way to go here?
Don't you have access to the server side, to just change the links there?
Because users with JS disabled would still see and use https, I don't think you should tackle the problem using JS.

Categories

Resources