Mac safari open a URL in new tab/window using javascript - javascript

The requirement is I get URL of excel file in webservice response. I want to open this URL in new tab/window using javascript.
window.open(url, '_blank');
doesn't work in mac safari.
I also tried creating <a> with target="_blank" and trigger click.But it didn't work with Mac safari.
Is there any way to achieve the requirement?
Open the excel file in some specific div will also serve if it is possible.
Thanks.

Do you have a popup blocker installed ? if yes then read this . Safari/Chrome have built-in pop-up blockers that stop this from working. The only javascript that is allowed to open a new window in Safari/Chrome is javascript directly attached to click handlers (and other direct user input handlers). In past versions people figured out some ways to cheat (like generating some other element -- a form or div -- and simulating user input with javascript), but newer versions are smarter about detecting this. I'd recommend re-configuring things so that you don't use a delayed pop-up -- that is the kind of thing that can generally be jarring to a user after all.

Related

Is it possible to open a new URL in Safari from Chrome if the page is being viewed on an iOS device?

Let’s say I have a webpage and it has a button with an HREF attribute. I want the HREF of that button to be opened on Safari browser if the button is being clicked from an iOS device, even if the user is accessing the page on Google Chrome.
As of now, I only need to handle this situation for Chrome and not any generic browser. The way I see it, there are two parts to the problem:
Identifying the OS of the Client Machine: This I might be able to do easily.
Opening the Popup on Safari from Chrome: This is the tricky part I am not sure if it is possible.
I am looking for possibilities of accomplishing the second part.
Short Answer: no.
Long Answer: Some iOS apps have defined URL schemes that can be used to access the app directly from the browser. For example, twitter://timeline. But Safari for iOS does not have one.
You can detect the OS the user is using and if it Chrome then suggest the user to open it in Safari and also provide the link where to download it from. Or you can also suggest the user to make safari their default browser. ( Also provide a link on how to do that to them).

Reloading iframe instead opens new tab - Firefox 21.0

I made a small webpage for some of my friends, and one of them is having an issue.
I'm using javascript to reload an iframe like so:
↺ Repair
Using jQuery, but for one of my friends using Firefox 21.0 on Windows 7, this causes the page to instead entirely change to the iframe itself; specifically, the livestream widget.
Livestream tends to bork fairly frequently, so the repair button is fairly important to the watching experience. Is there a way I could implement this differently so this doesn't happen to him?
Try binding to the click event instead:
HTML
↺ Repair
Javascript
$('#repair').click(function(e){
var pl=$('#player iframe')[0];pl.src=pl.src;
return false;
});

Download a file in hidden iframe: Android equivalent in Comet context?

I am currently using the following JS code to trigger a file download without leaving the page I'm on:
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
iframe.src = "/somefile.zip";
It works well pretty much everywhere I tested except on both the stock Android browser and Dolphin, where the download doesn't start at all. So far so good, after some research this hidden iframe trick happens to be known not to work on the Android browser.
But I tried several other methods to trigger the download on the Android browser, including window.open() (not reliable because popup blocking is enabled by default), or <a target="_blank"> with a simulated click() (which from a popup blocker perspective amounts to window.open() and gets blocked), or document.location = ... which downloads the file but breaks my app.
The problem with the latter document.location = ... is that this is a Comet application (server-push / long polling) so I really can't leave the page I'm currently on (and "leaving" includes changing document.location even for a file download, even if apparently the browser stays on the current page) otherwise the long polling connection is stopped and the updates stop, the app breaks. This obviously also applies when clicking normal links, either manually or simulated.
So in order not to break my app I really need to trigger a file download without leaving the page I'm on. Unfortunately I didn't find any viable solution that also works on the stock Android browser.
Any ideas?
Thanks for reading me.
Try using the anchor and simulated click without using a target=blank
I say this because I had a similar download consisting of an iframe and a simple link as fallback. The iframe worked on everything but the android, but the simple link would download successfully without leaving the page.

Catch "Back" event in browser and load different content

I've been working on a project using the hashbang (#!) method to skip though pages. Basically there is only 1 page, and when you click to go to a diffrent page, you stay on the page, but the URL changes, e.g. from index.html#home to index.html#about and new content is loaded via AJAX/JSON. All works well, but if I go "back" (or forward) in the browser, only the page in the URL changes, but my jQuery isn't fired to reload the content.
What I need is some code that will handle both the back and forward actions in all browsers, so that I can fire the function to load the page from jQuery. How do I do this?
Why reinvent the wheel? History.js is a great & well-maintained jQuery plugin that supports the new HTML5 History API and falls back gracefully to using hash URLs instead when the History API isn't supported. Works in just about every browser (even IE 6).
Take a look at the hashchange event. It fires when the hash is changed. However, you should only do this for Internet Explorer 8 support.
Internet Explorer 7 does not support hashchange, so you can't rely on that. As for Internet Explorer 9, it (along with Chrome, Safari and Firefox, of course) supports the History API, which you should be using instead. It keeps your URLs clear, short and semantic, while enabling elegant Back/Forward button support.
There is a jQuery-Plugin that seems to be doing exactly what you want.
http://www.asual.com/jquery/address/
It was the highest voted answer for the questing What is the best back button jQuery plugin?

Programmatically Calling Browser Right-Click Menu Options?

I would like to be able to programmatically invoke the right-click menu options, initiated from user events like rollover and whatnot of course. Is this possible?
Specifically, I would like to be able to call the Safari "Use Image as Desktop Picture" or the "Add Image to iPhoto Library", or the Firefox "Set as Desktop Background" using pure Javascript, so you don't have to right click. Is that possible?
You can't and this is because of security limitations.
If you could do that, malicious websites can access your browser and tamper with your system.
As far a I know, there is absolutely no way of doing this in a generic form using pure Javascript. You would have to build extensions (or maybe a Greasemonkey script for Firefox, I don't know) for each browser.
I seriously hope you can't do that... No website should be able to touch my desktop picture or iPhoto library.

Categories