window.open doesn't open in same session - javascript

I'm using the below anchor tag on a JSP page to open another page from the same application, but the new window is not opened in the same session and instead it redirects to the login page of my application. Any clues why?
<a href="#" onclick="window.open('/path_to_same_page', '_blank',
'toolbar=0,status=0,resizable=1'); return false;">Click here...</a>

Try this workaround, not sure it will help but worth a shot:
Click here...
By having this, the window won't get opened by script initially, but rather by the target attribute.

Reason behind this behaviour is, the parent page is hosted on a IE web browser control embedded in our windows application. When it creates a new window (either using window.open or target="_blank"), the new window is owned by iexplore.exe process and doesn't inherit the session cookies from the parent IE window, which is owned by our application process. There is no generic solution to this problem. In our case, we used some kind of Single Sign On to share the session context between two window instances.

You stated in your answer that
the parent page is hosted on a IE web browser control embedded in our windows application
There actually is a solution to this problem. Your application needs to handle the NewWindow2 event in order to maintain the session across windows.
Refer to the following MSDN resources for details on this:
How to use the WebBrowser control NewWindow2 event in Visual C#
How to use the WebBrowser control NewWindow2 event in Visual Basic .NET
How To Use the WebBrowser Control NewWindow2 Event (for Visual Basic 5.0 and Visual C++ 5.0)

first encode that url with encodeURL(""); and then add in javascript file

Related

Opening Custom Protocol in FireFox Browser..!

I have created a custom Protocol myapp: just like mailto: which opens one exe at client side using JavaScript. So, whenever that JavaScript I call there opens a dialog box asking for selecting the application through which I want to open.
I just wanted to set the default application through which it opens in the code and doesn't open that dialog box. I know that I can manually change from always ask to set default in setting of Mozilla Browser, but I wanted it through Code. so that user does not have to do any thing.
Is it possible? If yes, please guide me how I can achieve this.
You cannot set such settings from an unprivileged webpage, that would be a huge security issue.
What you can ask the user from a webpage is to register a web application as a custom protocol handler, but not an exe. However, if that exe is written by yourself, you might just register it as a protocol handler within the OS.

How to detect URL scheme and prevent the default navigation to that URL in phonegap hybrid application

I have the following requirement for my application (Android, iOS):
When the application launches it displays a login.html page (which is part of the application). After logging in, the application's webview should be occupied with home.jsp from an external domain. When user clicks on logout button in home.jsp it has to navigate back to login page . On click of logout when we usewindow.location.href="login.html" then it tries to find the page on xxx domain.
Is there a way to detect this navigation URL and override the URL from javascript or phonegap properties in the application?
When I inspect window.location.href in an android emulator I get file:///android_asset/www/index.html
But I think Nathans idea of moving it to the server is a good one. You could also have one on the device if you really need to. (PErhaps you should ask the person specifiying the app achitecture how they would do it :) )
The answer is going to vary depending on how you've implemented the mentioned WebView where home.jsp is being displayed in. You did not provide any code or any specific information so the answer is going to be the same - somewhat vague...
If you've opened a new WebView, then you can't control it from JavaScript. You'll need to control it via Java or Objective-C code (you did not mention which environment you're developing for...).
For example, if you'll look in the your-app\android\native\src\com\your-app\your-app.java file, you'll see how the native layer loads the application's index.html file after the Worklight JavaScript framework has been loaded.
Similarly, you could re-use this approach in your own application to close and re-load login.html.
If you're in fact doing the mentioned re-direct from the comments, meaning you're re-using the current webview but replacing its content with external content, then I think it is expected that you've lost the context of the application, and when looking for login.html - it doesn't find it... because you've moved from app-context to web-context. They do not know each other.
I think you should not do this re-direct. Instead, you need to open a new WebView using a Cordova plug-in, and in this new WebView to display your external content.
In this Overlayed WebView, you can detect any urls that are clicked on and if the sign-out URL was detected, then close the WebView.
You can see parts of this in action in the Integrating server-generated pages in hybrid applications tutorial and accompanying sample project.
In the sample project, you can see the functions provided (where you can add yours) in android\nativeResources\src\com\IncludeExternalPages\IncludeExternalPages.java.

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?

"Silently" invoke helper application using Javascript

Can Javascript cause browsers generally (and Chrome for Mac in particular) to invoke an external helper application for a URI without opening a new tab/window, or navigating away from the current page?
The context is that I am developing an extension for Chrome that occasionally needs to invoke particular actions outside of the browser. Using the rather neat trick described here, the extension only need open particular URIs to invoke suitable AppleScript.
However, how should one open such URIs from a script running in an extension's background page? I don't think XMLHttpRequest will help, as Chrome won't (shouldn't?) attempt to use an external helper application for XHR; nor does it appear that setting window.location.href has any effect on such a background page (it is not a problem if the background page is unloaded).
My current solution is to open a new window, but it's unnecessary and rather distracting for the user.
There are a few options here:
You could write an NPAPI plugin.
You can use a WebSocket client in the browser, and run a local server on your desktop. That way you establish a tunnel to your local machine to do pretty much anything you want there.
I did this for relaying global media key presses to control web-based music players and wrote it up. Source here.
I just realised I can do this with an <iframe/> in the background page. Très simple!

How to write live testing app for HTML and JS and capture page load events

I'm writing an in-browser Chrome app that will allow users to edit HTML and JS code and then be able to test their changes live.
My current method of doing this is to create a new window with JavaScript, create an IFrame in that window, and then inject the user's HTML or JS code into the IFrame. The problem with this though, is that the page load events of the IFrame can't be used by the script being live-tested. My app could manually call testWindow.iframe.contentWindow.onload, but that wouldn't work with the various events and methods used by the different JS libraries for their "domready"-style events.
Perhaps this is not possible, and I'll just have to send the code to the server and have the server output it. I noticed apps like jsfiddle actually just ask what library and event you want.
Any ideas on how I can have live-testing in my app and still fire page loading events for the JS being tested?
You could use dispatchEvent on the iframe, which you know will be supported since you are making a Chrome app. Alternatively, for absolutely certain cross-browser compatibility (or some other reason) you could also send the script to your server (using Ajax) to be stored in a database, then linked to in the new window.
Just heard a lightening talk on http://vowsjs.org/ this evening. Haven't used it yet but I plan to explore this for testing web apps.

Categories

Resources