Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
735 views
in Technique[技术] by (71.8m points)

ipad - javascript window.open in safari

I've run into an issue with opening a new window in safari (both ipad and desktop versions) that revolves around the popup blocker. Basically I've found that if window.open isn't called from a click event, safari will block the popup.

The event that is calling window.open is currently onchanged from a list box.

Is there any way other than switching which event we handle to trick safari into allowing a popup in this scenario? (the onchanged event)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The safari has a pop-up blocker silencer not show when a link is blocked.

To check if the pop-up blocker is active, go on safari settings > security > something like blocking pop-ups.

To cross it in a simple way, since I can not open a new window, I display an alert showing pop-up blocked.

In my case, I use select inputs to open external links:

HTML

<select id="retailer" class="windowOpen retailer-submenu">
    <option value="null">Select one</option>
    <option value="http://amazon.com">Amazon</option>
    <option value="http://ebay.com">eBay</option>
</select>

Javascript

<script type='text/javascript'>
    $('select.windowOpen').change(function(){
        var url = $(this).val();

        var open = window.open(url);
        if (open == null || typeof(open)=='undefined')
            alert("Turn off your pop-up blocker!

We try to open the following url:
"+url);
    });
</script>

The code to check if a pop-up is blocked is just this:

var open = window.open('http://google.com');
if (open == null || typeof(open)=='undefined')
    alert("Turn off your pop-up blocker!");

PS: the jquery trigger did not work with me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...