<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jens Arps &#187; safari</title>
	<atom:link href="http://jensarps.de/tag/safari/feed/" rel="self" type="application/rss+xml" />
	<link>http://jensarps.de</link>
	<description></description>
	<lastBuildDate>Tue, 01 May 2012 12:00:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Safari and window.open – How to do it</title>
		<link>http://jensarps.de/2009/10/08/safari-and-window-open-%e2%80%93-how-to-do-it/</link>
		<comments>http://jensarps.de/2009/10/08/safari-and-window-open-%e2%80%93-how-to-do-it/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 10:22:07 +0000</pubDate>
		<dc:creator>Jens Arps</dc:creator>
				<category><![CDATA[Browser Struggle]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://jensarps.de/?p=50</guid>
		<description><![CDATA[There is still some traffic coming in from people who are searching for how to deal with the safari popup blocker. So I thought it might be nice to also tell what you can do about it – as most people want solutions, not backgrounds… So, here you go: It&#8217;s pretty simple, really. What to [...]]]></description>
			<content:encoded><![CDATA[<p>There is still some traffic coming in from people who are searching for how to deal with the <a href="http://jensarps.de/2009/08/21/safari-and-window-open/">safari popup blocker</a>. So I thought it might be nice to also tell what you can do about it – as most people want solutions, not backgrounds…</p>
<p>So, here you go:</p>
<p>It&#8217;s pretty simple, really. What to do? Well, call window.open() while the popup blocker still allows it, and store a reference to the window object. Then, later, do with it what you want. That is, changing the location in most cases.<br />
<span id="more-50"></span><br />
Huh, that&#8217;s all? No magic? Nope, sorry. The popup blocker&#8217;s rules cannot be bent.</p>
<p>Say, you have a connection like this (I stay with the example code of the prior post):</p>
<pre>dojo.connect(dojo.byId('b9'),'onclick',function(evt){
    dojo.publish('/opener/callOpen');
});</pre>
<p>Then call window.open in your subscription:</p>
<pre>dojo.subscribe('/opener/callOpen',function() {
    var winRef = window.open();
    dojo.xhrGet({
        url: window.location.href,
        load: dojo.hitch(opener,function(){
            this.open(winRef);
        })
    });
});</pre>
<p>And let your open() know there might be a window object coming in:</p>
<pre>opener = {
    open: function(windowReference) {
        var newWin = windowReference || window.open();
        // see if we get a window object
        console.log(newWin);
    }
};</pre>
<p>In case your new window will be open and visible for some time until you can work with it, don&#8217;t forget to let the user know that the window will get some content in a few, e.g. point the new window&#8217;s url to some nice &#8220;please wait&#8221; page.</p>
]]></content:encoded>
			<wfw:commentRss>http://jensarps.de/2009/10/08/safari-and-window-open-%e2%80%93-how-to-do-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Safari and window.open</title>
		<link>http://jensarps.de/2009/08/21/safari-and-window-open/</link>
		<comments>http://jensarps.de/2009/08/21/safari-and-window-open/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 21:10:22 +0000</pubDate>
		<dc:creator>Jens Arps</dc:creator>
				<category><![CDATA[Browser Struggle]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://jensarps.de/?p=5</guid>
		<description><![CDATA[Update: If you are interested in how to make window.open work you might want to also read the follow-up: Safari and window.open – How to do it Working on a project these days, I noticed that the only call to window.open in that app did not work in Safari. Looking into it, I found that [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_20" class="wp-caption alignleft" style="width: 160px"><a href="http://jensarps.de/wp-content/uploads/2009/08/safari-console-screenshot.gif"><img class="size-thumbnail wp-image-20 " title="safari-console-screenshot" src="http://jensarps.de/wp-content/uploads/2009/08/safari-console-screenshot.gif" alt="Safari console screenshot" width="150" /></a><p class="wp-caption-text">Safari console screenshot</p></div>
<p><strong>Update</strong>: If you are interested in how to make window.open work you might want to also read the follow-up: <a href="http://jensarps.de/2009/10/08/safari-and-window-open-%E2%80%93-how-to-do-it/">Safari and window.open – How to do it</a></p>
<p>Working on a project these days, I noticed that the only call to window.open in that app did not work in Safari. Looking into it, I found that it was Safari&#8217;s popup blocker that wouldn&#8217;t let that call succeed.</p>
<p>Usually, I don&#8217;t deal with window.open, so that behaviour was new to me, and I asked Mr. Google what he knew on this. Not much, as it turned out out – I found only two interesting notes on it. One was pretty strange and I guess it was more about a Safari 3 beta not returning a window object. The other one proposed the the window.open call had to be within the same function body as the method handling the event. The comments on that post affirmed this suspicion, but I decided to look into it myself.</p>
<p><span id="more-5"></span></p>
<p>So I threw some buttons on a page and started connecting&#8230; Ah, that&#8217;s not entirely correct, I started with typing &#8220;window.open&#8221; into the console – to no avail, Safari didn&#8217;t do a thing.</p>
<p>Then I put the window.open call into an &#8220;onclick&#8221; attribute to make sure my Safari would open windows at all – yep, it did. Good. Ok, so I moved on, step by step to see when Safari drew the line.</p>
<p>Next were some basic connects using dojo.connect. All good. Then connections to anonymous functions calling window.open – all good. Connections to anonymous functions calling an object&#8217;s method that was calling another method that was calling window.open… still all good. So far for the theory the window.open call had to be in the same function body…</p>
<p>One step further: using dojo&#8217;s pub/sub system. So I connected a button to an anonymous function that published a topic, and subscribed to that topic, in different manners. Still Safari opened a new window every time, as ordered.</p>
<p>Finally, I tried callback functions. First, as an argument to dojo.xhrGet, then as an argument to setTimeout. And – bingo! Safari silently refused to open a new window. Phew. Ok. Well, at least I do know now.</p>
<p>The only tiny problem left, concerning the scenario present in that app I mentioned before: a callback is <em>needed</em> there. Some data is sent to the server and the new window can&#8217;t be opnened until the app recieves the response… And I don&#8217;t want to tell customers to turn off their popup blocker – especially since Safari doesn&#8217;t have site-specific settings for it&#8217;s popup blocker.</p>
<p>The file containing the tests can be found <a href="/tests/safari-window-open.html">here</a>.</p>
<p><strong>Update</strong>: How to work around the popup blocker: <a href="../2009/10/08/safari-and-window-open-%E2%80%93-how-to-do-it/">Safari and window.open – How to do it</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jensarps.de/2009/08/21/safari-and-window-open/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

