What is the scope of window.name in IE? - javascript

We have a product that has both a winforms and a web client, and are providing the users a way to launch into another company asset (a web application). We need to make sure that the user only ever has one instance of the other web application open in a browser (or at least that we've opened for them). We accomplished this (sort of) by doing the following...
In the winforms client, we have a hidden WebBrowser control that, when the user clicks the button to launch the other app, we write a small HTML page into the DocumentText property that contains:
window.open('http://othersiteurl', '**sitename**').focus();
In our web client when the user clicks on the same button we do something similar:
window.open('http://othersiteurl', '**sitename**');
From only one client or the other this works surprisingly well. Where things get sticky and weird is when you try accessing it from both clients. If you launch the other product from the winforms app first, it launches a new window, and any subsequent launches of the product from either client load in the instance that's already open. But if you do it the other way around, and start from the web client, the first instance launches in a new tab in the same window, but then every launch from the winforms client goes to a new window!
I'm using the same value for the 'name' parameter of the window.open in both clients. It's bizarre to see it work so horribly different. Can anyone explain how the 'name' parameter is scoped in IE? (yes, this is IE-only...the WebBrowser control hosts IE, and our product is IE-only) When launching from the winforms client first it seems to be global to all open instances, but the other way around makes it seem very much the opposite.
Any ideas?

Have you tried window.createPopup? Dunno if it would work any better, but if you don't need the "chrome" it might be worth a shot. For more info check out the MSDN:
http://msdn.microsoft.com/en-us/library/ms537638(VS.85).aspx

Under IE7, and prior versions as well to my knowledge, the name parameters is scoped to a particular instance of the IE process. Typically, starting IE manually creates a new process. Any windows that are created via js or even clicking the "New Window" button within IE, creates a new window that is still running under the current process. Under this condition, the name is in scope across these windows.
When you have a desktop application spawn an instance in the way you mention, it is opened under a new process. Depending on the framework (.NET, etc) it may reuse the process once it has a handle to the first, or it may create a new process for each call. It sounds like, from your initial testing, that the first is the case, where the application will reuse the process.
That being said, I am not sure what kind of process you may have to implement to check for the name "cross-process". One option, depending on what kind of control you have over the web application they are accessing, could be to have the server keep track of a list of user to session ids and when a second entry shows up for a user, that means they have a second browser open, and handle appropriately from there.

Related

Can JS be used to check for and log temporary page changes by end users via dev tools or the console?

The setup for this will be a Chrome instance on a VM I control (and thus can install anything I need onto it) for the purposes of monitoring changes to a web page that were not made by the web code itself. I will be testing a web site (on a Linux build, in Apache using a Tomcat or Jetty instance) which displays data from a backend database (I won't bore anyone with the details). That data once displayed can of course be edited by anyone who knows how to use dev tools and inspect element features in certain browsers, and while the changes made won't propagate back to the backend and can be wiped out with a refresh, I would like to monitor to see if those changes were nonetheless attempted.
I have already managed to find a way to monitor if the Dev Console has been opened using Chrome by using an extension that specifically hooks into its' toggle. Coupled with some JS code, I can then act upon when it is opened, closed or both, and for example, force a refresh of the page in the event that someone used the inspect element to make changes to the rendering of the page.
I would like to then check to see if any of the client-side elements have been altered, capture the changed values, and then retrieve the original data from the back-end to compare against (I can manage the back-end stuff). I've seen a few examples of the use of InnerText and InnerHTML as a means of checking, and will try it out later, but wanted to know if anyone had any experience with anything similar.

How to keep js function run between different pages?

I wonder how sites like SoundCloud work: you play a song and it keeps playing even if you move to another page without stopping
Any suggestions?
The only way I can think of is to build your app, or at least the parts of it that need to bo continuous, as a single page.
In practice, this means that only one HTML document is loaded. When, say, a link is pressed, the browser action is intercepted and prevented and the browser behaviour is faked by javascript.
Consider a website consisting of pages A and B. Normally, when a link pointing to B is activated, the URL is changed and the browser calls the server, requesting B. In a single-page application, however, this is interrupted by a javascript function, which changes the URL using the History API, and then displays B in a way that doesn't require a new document being synchronously fetched from the server.
There's a couple of ways to do it.
Navigate to a new page
If you do that, a whole new JS execution context is created for the new page, so you can't keep the function running. What you can do however is to "resume" execution in the new page. For this you need to save the state of the old page either on the server or in some client storage that persists between page changes (cookies, localStorage, etc).
Fake navigation
This is the most user friendly way - you turn your website into a web application. You no longer have multiple pages, so when user wants to change what he sees in the browser (like go to a new song), the app simply changes the appropriate area with the desired content. This is a complex topic that should probably be researched in itself, not explained in a SO answer. Go ahead and google "single page application" and you should find plenty of resources for it.
Technically you never change the page when you are using souncloud. You always stay on the same page and only the parts get changed which are actually changing, so you never reload the whole page. That's why they can keep the music playing: They just never remove or change the actual player. If you are wondering why the URL in your browser is changing if you never leave the page: They manipulate your history entries.
If you are interested in creating an application that behaves similar you should checkout frameworks like Ember.js or Angular.js. TodoMVC Gives a nice overview of those frameworks.

Button Navigation in Windows 8 App

I am really new to Windows 8 App Development.I am creating a Windows 8 App in which I need to click a button and open another page. I am developing this windows app using HTML/CSS and Javascript. How can I navigate to another page using a button click? I have tried several with window.ways which I can use with HTML/Javascript for Browser web pages. But non of them are working. Is there a special way to do this in Windows 8 App development? Can anybody please explain with an example.
Thank you.
I could guess that maybe your problem is in understanding the different contexts? A page can run in the "local context" which gives it the permissions of your app and access to the Windows 8 API. A page can instead be run in the "web context" in this context it does not have access to the Windows 8 API but can execute remote code.
Basically, you start in the local context...code that is part of your app. From there, you can link to pages in your app's package (these would run in the local context). You could also link to things outside of your app package (these things would run in the web context). The confusing thing is when you link to something in the web context. Basically, since replacing the current page/screen with the web-context would make you lose all access to the Windows 8 API, when you link to something in the web context, Windows 8 won't replace the screen with that page, instead it will open up IE10 and load the page in there; That way you don't lose control of your app. The trick to loading stuff in the web context is to load it in an iframe which is in the web context. But you always need to keep the main page itself in the local/app context.
For your reference:
Urls starting in "ms-appx:///" load in the local context.
Urls starting in "ms-appx-web:///", "http://" or "https://" load in the web context.
As far as I remember, if unspecified, links are in the same context as the page they are in.
In terms of how to do it...you should be able to use <a href="..."> as well as the usual javascript ways. It's been a while since I've coded for Windows 8, but I don't remember that part being different from how I did things in normal web development.
Unless of course you are talking about the PageControl object or the navigation template. So many things. Either way, I strongly recommended getting the free book "Programming Windows 8 Apps with HTML, CSS and Javascript" by Kraig Brockschmidt. It's an easy read full of examples and I'm sure that will solve 99% of your questions if you are new to this.
So you tried the
href="____.html"
try dropping the ".html" so it is just
href="____"
And do you have the controller to handle it when you tell it to go the page?

javascript urls in IE pinned site task list

I'm attempting to set up Pinned Site features for my project. The trouble is that I'd like to have the tasks be javascript actions rather than loading a new page. The reason for this is that the site is designed to only ever work in a single window.
I tried adding the following META tag:
<meta name="msapplication-task" content="name=Test Action;
action-uri=javascript:ui('test',8);icon-uri=/img/icons/test.ico" />
However this causes the task to simply not appear. (Using a normal URL makes it show up just fine)
Is there any way to do this? The best I can think of is a hash and check for the hashchange event, but this doesn't work because it gets opened in a new tab of the window...
I'm afraid this is not supported, because action list is designed for launching an application, not for a navigation inside it.
If you really want implement it, you can open a new window, send a message to server via web sockets and let server to forward that message to application window also via web sockets. But this is very hacky approach and works only in IE10.
This issue can be resolved by using a hash. By setting the action-uri to something readable by JavaScript, the JS can then read it, process the instruction, and then clear the hash in preparation for the next task.
This has the advantage that it works even when the window isn't already open, since the JS will read the hash on the first load too.
The catch is to add window-type=self to the content.

how can I launch/pass a value to a Windows C# application from a web page? (it seems possible with song links to iTunes)?

I'm putting together a C# winforms application, and it would be good to be able to have the ability for someone to click on a webpage link that automatically maximizes my c# application and passes some data to it. Pretty much like I see some webpages have a song link that automatically opens iTunes, and then in iTunes it searches for the song details you passed.
Q1 - How does one do this in HTML/Javascript?
Q2 - Does this approach only work on certain browsers?
Q3 - Would this only work on Windows? (I just need it for windows myself)
Thanks
You can register a URL protocol handler (see) which allows you specify a unique URL protocol and you can make clickable links in web pages which will spawn a new application passing the complete URL. Be careful though because this mechanism has been mis-implemented a number of times which can expose you to exploitation.
Also browsers will normally warn you if you are trying to use one of these odd URLs. And this will only work on Windows (but there are alternatives on other OSes).
You would have to associate a new file type with your C# application. The web page could "launch" such a file by downloading it.
I believe you'd have to pass parameters by writing them to the file to be downloaded.
It's true that there would be a "run or save" prompt, but aside from that, I think this would be the simplest method, and the one that would be easiest to maintain.
My first reaction would be that you'd have to create some kind of browser plugin first, that would act as the middle man between your javascript and your C# application. This is because website javascript and other code is run in a limited security context and cannot access priviliged resources, such as other applications, named pipes, tcp ports, etc.

Categories

Resources