opening up a server location from a websitse - javascript

GOAL:
I have a business request that wants us to create a link so the user can open a server directory (in a file manager window) from a link on our website. We want them to stay on the same IE page. FWIW- this is in our salesforce environment
PROBLEM:
I am getting an irritating defect. That is, that the file manager window is opening up to a server, but i'm also getting a blank IE window to open up, which is a poor user experience.
Can someone help me with a way around this artifact?

Related

Opening a file from the default file browser on mobile device. No matter the browser

I have a web app that prompts the user to upload a file with some standard html:
However, if the user opens the link from the mini-chrome that opens links from hangouts/gmail. The file browser that is used is different from the file browser used by navigating to the page with chrome.
My question is:
Is there a way to set default file browser on the web?
I understand you can set the default application to open links in the gmail app, this is irrelevant as the user will click the link from an email and it doesn't make sense to tell them to copy the link into chrome.
Thanks in advance!

Save PDF when clicked on a download button without showing the OK/Cancel option to save

Is it possible not to show Open/Save dialog? I would like to save the pdf file straight to specific disk location on client PC. Need in NOdeJS
I am automating a LogIn in NodeJS which after a successful login, on clicking a 'Download Report' should download the pdf directly to the computer. On manually testing it does so. However when i run my script after clicking the 'Download Report' it would give a javascript popup for confirmation to save. –
EDIT: After reading your comment again, I noticed you are adding some settings to your profile that sound like they should make it do what you want. Since it isn't working, I think it would be good for you to try what I describe below.
END EDIT
You stated in a comment that you are using Selenium Webdriver to do the login automatically, and the download popup only appears when Selenium is driving the browser. The reason it doesn't keep your settings (to not show the popup) when Selenium is in control, is that Selenium creates a new profile, which has the default settings. You will need to manually create a profile for your browser (I see you are using Firefox), open Firefox with that profile, change the settings to not display the download popup, and tell Selenium to use that profile when it runs.
I'm not sure what your environment is, but I run Selenium from linux, so to create a new profile, I run Firefox from the command line with a -P flag, which opens the profile manager. If you use windows, you may need to look up another way to do this.
Once you have the profile created, and have changed the settings appropriately, change your code to the following:
FirefoxProfile profile = new FirefoxProfile(new File("path/of/firefox/profile"));
Hopefully that will work for you.

how to find particular site is already open or not in the browser?

I have sent Email to My client with some links.. (http://example.com?id=1234).
When the User click this link, It will open a new tab and play same Video's using iFrame.
if the site is already open, no need to open a new window, and just launch the video on the already open window.
if the site is not yet open, then open a window with the site and play.
How can i find the site (http://example.com) already opened or not?
Is there option in JavaScript?
There is no way to run any client side code in an HTML formatted email. So this is impossible.
The closest you could come would be to:
use some kind of token to identify a user (e.g. stored in a cookie)
run some heart beat code to see if they are still on the page (e.g. use XMLHttpRequest to request a 1 byte file every 15 seconds using a page id generated when the page was loaded and the user id in the cookie)
check on the server to see if a heart beat from a different page was received recently when a new copy of the page is loaded
serve different content if it is
For security reasons this is not possible directly in JavaScript.
But you can work around and add a marker in the URL then detect server side if the site is already streaming the video to that computer (match with URL marker, IP and browser).
Upon response the server can say close or not...

Javascript reads previously opening tab html on the save Window

I have a task that i do not know where to start, i hope Stack Overflowers can give me some ideas.
I want to read the html source code of the previously opened and still opening tab in my web page.
My approach was to grab the url of the targeted page, send that url to server and do something, then use it in my web page. But i am facing the "same domain policy" on the server side, i know that JSONP can be used, but i must use POST in this case (other reasons). So i think if the tab (page) has been opened and is still open, there must be some ways that i can read the HTML when my web page is opened.
The flow will be if there is Page1 opening, user opens mywebpage.html on the same Window, mywebpage.html finds there is Page1 opening, then grab the HTML source page and use it.
Thanks!
Edit:
This is the full story.
What I am planning to do is a FireFox plugin. And there is a Button (myPluginButton) on the tool bar.
If user click myPluginButton, the HTML code of the current page will be sent to the server, then server parse the HTML code and generate a report, a new tab then is opened to display this report.
My current approach is to read the HTML of current page using newTabBrowser.contentDocument and send it to server, then do the parsing on server side. But this approach creates extra traffic. The efficient way would be only the url of the current page is sent to the server, and we can read HTML and parse it on the server side. However, the same domain policy does not allow me to do this easily.
So, my question is if it is possible to do when user click myPluginButton to open a new tab, this new tab loop all the opening tabs on the browser and reads the HTML contents of them then generate the report, since these tabs are still opening and the HTML contents must be saved on somewhere ( or i am wrong).
Thanks.
The browsers have a built in protection called same origin policy that prevent a page to read the content of other origin(domain, subdomain, port,...)
If you want to gain access to the current page you can use a bookmarklet.
You ask your users to add it in their bookmarks bar, and each time they want to use it, they don't open a tab but click on the bookmark.
This will load your script in the page, with all access to read the page content.
And oddly enough you can POST from this page to your domain, by posting a FORM to an IFRAME hosted on your domain. But you won't be able to read the response of the POST. You can use a setInterval with a JSONP call to your domain to know if the POST was successful.

How do you get a spreadsheet to open Excel instead of a browser window?

If you call javascript window.open and pass a url to a .xls file it open on some machines in the browser window. How can you force it into Excel?
Only the users machine can "force" it into Excel. That said, 99% of the time if you send the correct mime-type and a user has Excel, then it will open in Excel assuming they approve.
And only the server can send the correct mime-type. The document type you pass to a JavaScript window.open call will have no effect on this. In fact, calling window.open will at best just open a superfluous window.
It's best to just link to the document with <a href="foo.xls">. And provided your server is sending a mime-type of application/x-excel or application/x-msexcel this will almost always nudge the browser into opening a new window with the Excel document.
If it's just a static file, and you're using Apache on Linux, check for a file called /etc/mime.types, and ensure that it has the following line in there to associate the .xls file extension with the correct MIME type:
application/vnd.ms-excel xls
I'm guessing the location of that file might vary across systems, but it's in /etc/mime.types on my server which is running RHEL4.
AFAIK you can't do this with JavaScript alone. If you have some sort of scripting language on the server's side you can alter the header to force a download.
Here's a simple tutorial in PHP, but you can easily find one in your favorite language.
You cannot force it into Excel. You can allow the browser to handle it whichever way it is configured to do so, or you can try to force it to download the file and let the user open if from their desktop. To force a download, search for "force download" and your server-side language (PHP, ASP.NET, JSP, etc.)
I don't think you can: you cannot call external programs using Javascript for security reasons. Assuming that the user has Excel installed, you may want to open the new window without the address bar to give the user "the illusion" that the file has been opened with Excel in Internet Explorer.
I wouldn't think this is possible from javascript due to security issues, there would be nothing stopping a rogue webpage from opening dozens of excel/word instances.
Could you not set a hyperlink to the url of the .xls, that way the user would get the usual download prompt to view the file.
Set the http content type to the Excel datatype: application/vnd.ms-excel
You shouldn't need to redirect to a new window, but you will get a popup asking the user to save or open the file.
In relation to (2): I'd worry if a browser could launch an external application and load data into it automatically without user intervention.
This is a setting in each user's browser and not in something that can be set by code. So unfortunately you do not have control of that.
You can not, as it depends on the client machine.
For example on Windows if you want it to always open it with Excel, not in the browser window, you have to open My Computer, Tools, Folder Options, File Types, select the XLS type, and click on Advanced. There are two checkboxes: Browse in same window and Open web documents in place. Uncheck both, close browser window, open it again and try again.
However as I said: it depends on the client, you can not force it.
You can do this using LaunchinIE, an ActiveX Control that will enable HTML pages to start whatever application on the client's machine, without security warnings.
Quote from the site: "At last, web pages can start Word, Excel, or any other corporate application without complaints. Securely."
For this you do have to install the control on the user machine and also add the URL that is allowed to execute local applications to the Windows registry.
Another quote from the site: "To ensure security, LaunchinIE needs to be carefully configured client-side; due to this restriction it's only fit for intranet use."
I use LaunchinIE in our training facility so I can use Internet Explorer as a menu which lets the user choose the machine setup. LaunchinIE then calls a batch script that configures the machine to best support the selected training.
Here are the steps to get this pop-up back when opening a saved Excel file.
Right-Click on the windows [START] button and select Explore to open Windows Explorer window will open.
From the menu select Tools \ Folder Options…
• Choose the File Types tab and scroll down the list of files.
• Left-Click to highlight the XLS Microsoft Excel Worksheet file extension and click on the Advanced button.
In the Edit File Type window, Uncheck the “Browse in same window” option.
Click OK button to accept your changes.
Start a new browser session. The next time you open your Excel spreadsheet in your Inbox, you should be prompted with the following window. Be sure to leave the “Always ask before opening this type of file” as checked. Clicking the Open button should now open your file in Excel.

Categories