Closing current browser window/tab using JS - javascript

I’m developing a small web app, and I want to add a ‘close’ button.
The app runs inside Chrome window, and runs from a desktop shortcut (there's no opening window).
I’m using AngularJS on client side & NodeJS backend.
Every solution I've tried:
$window.close();
$window.self.close();
$window.open(‘’, ‘_self’, ‘’); $window.close();
Returns this error:
"Scripts may close only the windows that were opened by it."
Any other creative idea how to bypass/hack this restriction without setting the browser’s configuration?
Thanks.

Related

how to enable javascript of remote web page in electron app popup browserwindow

I have an electron (4.0) app. I'm using the openid/appauth-js node module.
This module brings up a native browser window when performing openid connect hybrid flows.
(I am using IdentityServer 3 for the server)
I want to use an electron BrowserWindow instead.
The flow works up to the point where the consent screen is shown.
The consent screen has a minified version of jQuery (v1.11.0) followed by Bootstrap (v3.0.3).
The page displays fine in native browser, but in electron I get the message "Bootstrap requires jQuery"
I've tried set the browserwindow option nodeIntegration:true (I appreciate this is overkill). I've partially looked at pre-load aswell, but I think this is undesirable as the web service could be used by other clients.
I've also tried --enable-sandbox together with sandbox: true, but this breaks the main window.
I've also tried debugging the javascript code to identify why it fails to run correctly, but its complicated due to the openid flow interaction.
I require the popup window to execute remote resource javascript like a chrome or other mainstream browser.
Instead Bootstrap fails to recognise jQuery is already loaded

Calling dialog api opens a browser when using Word inside Microsoft Teams

In Microsoft Teams on Mac (maybe also on other versions) you have the possibility to edit a document inside Teams. This will open an instance of Word Online.
We have a Office web add-in that utilizes the dialog API to login in to our service. We open this by calling Office.context.ui.displayDialogAsync(_UrlGoesHere_). However, when inside Teams, this method will not open a dialog, but instead use the behavior of Word Online (as if you were in a browser) and launch a completely new browser window.
This means that we lose the connection between the addIn and the login dialog because the browser window is no longer a child of the web add-in taskpane and it's therefore not possible to make any callbacks to the addIn.
This seems like a misbehaviour in Word/web add-ins? Or should this be done differently when inside Teams?
Thank you!
The reason you're seeing the behavior of Word Online is that you're using Word Online. When you're editing a document in Microsoft Teams, you're simply using Word Online within an IFrame.
Keep in mind that the native Microsoft Teams client is still effectively a web app. Teams is built on Electron which itself is built on Chromium and Node.js.
You could try using the displayInIframe option of the Dialog API. Enabling this option will result in the dialog being displayed in an IFrame overlaying the editor rather than opening a new browser window. I'm not set up to confirm this will work when Word Online is embedded within and IFrame in Teams but it is certainly worth testing:
displayDialogAsync('url', {displayInIframe: true}): void;

Is it possible to programatically start application Performance test in web browser?

I would like to programatically start few Performance tests (like the one in Chrome Developer Tools in the tab, where you can click record button or hit Ctrl + E to capture a new recording). I want to do some performance tests in my application (on few views/subpages - it is SPA). However as I need to do them on different devices (PC, mobile phone) - I want to ask few friends to do it on their machines. But they are not programmers, so I don't want to bother them with writing any code or messing with dev tools, I just would like to send them application project and JavaScript script file. The only thing they will do is run application and that script, which will cause a performance test to be started automatically.
I wonder if Chrome Extension API (or Firefox API) expose sobe methods, or if it can be done via NodeJS (with some additional modules/libs included) - like NodeJS can get access to opened programs on Windows and capture that browser is opened with application started and then fire some event, which will start performance measurements?
Or maybe it is possible just from Dev Tools?
It would be nice if that script could also automatically save test results to JSON (like when you click right mouse button after test is finished and there are options to save and load Profile file) on device disk.

html shortcut on smartphones

I wonder if there is any chance, either javascript or some code, to know if the user is visiting the page on the mobile device directly from the navigator or from a shortcut from the home screen? I need to know this so show a message to invite the user to create a shortcut and then use the web page in the app like mode.
This page notes how you can tell for iOS; you have to set a meta tag to turn on standalone mode and then check window.navigator.standalone.
However, as far as I can tell, there is no equivalent for Android's built-in browser or for Chrome on Android. See the documentation for mobile Chrome: "How can I detect if the app is running as an installed app?
You can’t, directly." And also: "Do not prompt the user to add your app to the homescreen. There is no way to detect if the app is running installed or not."

NSURLConnection and Javascript

I'm trying to log in into a web page through an iPhone app. I'm using a NSURLConnection to try to connect. The app seems to be logging in correctly but I'm then getting redirected to a page that says I can't continue without Javascript enabled. I'm running all of this through the iPhone simulator that comes packaged with xcode. The curious part is that when I navigate to the same web page with the same information in safari in the iPhone simulator I don't get this reconnect, it sends me to the page I want.
Why is using the NSURLConnection giving me this redirect if I have Javascript enabled in the simulator and can navigate to it outside of the app? Thank you for any help.
NSURLConnection does not interpret javascript. Safari does interpret javascript. If you need it to interpret javascript use UIWebView and actually display the webpage.
Your webpage should implement "graceful degradation". Which just means your site should work without any javascript. You can find plenty of documentation about graceful degradation if you google.

Categories

Resources