我发现GSA浏览器(Google Search App for iOS中的浏览器)看起来像JS兼容性问题。
用户代理示例:
AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/64.0.223374052 Mobile/15E148 Safari/605.1
AppleWebKit/604.1.34 (KHTML, like Gecko) GSA/65.0.225212226 Mobile/15D60 Safari/604.1
AppleWebKit/603.1.30 (KHTML, like Gecko) GSA/65.0.225212226 Mobile/14G60 Safari/602.1
在我的代码中,一旦用户单击我页面上的按钮,就应该打开一个新标签,其中POST
值是通过<form>
发送给它的用户单击按钮后,将使用以下JS代码生成此代码。
在除GSA之外的所有浏览器上都可以正常工作,在GSA上,它只是打开一个新的空白标签。
有任何想法为什么会发生这种情况以及如何解决?
HTML:
<label class="popup-button" data-tab-url="/next-page.php" data-tab-url-go="foo" data-popup-url="none" data-popup-url-go="foo">
Javascript:
(function($) {
var check_mobile = true; //
var button_class1 = ".popup-button";
var button_class3 = ".popup-button-flipped";
var currentPopup = null;
var currentPopupTab = null;
var currentPopupXhr = null;
var initOpenModal = false;
var checkUrl = function(url) {
if (!url)
return url;
return url.trim();
};
var getFormData = function(form) {
var data = {};
form.find(':input').each(function() {
var n = $(this).attr('name');
if (n) {
var v = $(this).val();
data[n] = v;
}
});
return data;
};
var w = null;
var wId = 0;
var tryOpenTab2 = function(button,tab_url,tab_url_data_go) {
var data = {};
var form = button.parents('form').first();
if (form.length > 0)
data = getFormData(form);
if (tab_url_data_go) {
data['go'] = tab_url_data_go
}
if (!tab_url)
return;
var form = $('<form></form>');
form.attr('method', 'POST');
form.attr('action', tab_url);
for (var k in data) {
var input = $('<input />');
input.attr('type', 'hidden');
input.attr('name', k);
input.attr('value', data[k]);
form.append(input);
}
$('body').append(form);
if (w && !w.closed) {
w = null;
}
if (button.is(button_class3)) {
w = window.open(window.location.href.split('#')[0] + "#" + button.attr("data-popup-id"));
} else {
wId = ''+new Date().getTime();
w = window.open('about:blank','myPopup_Window' + wId);
form.attr('target', 'myPopup_Window' + wId);
//wId++;
}
window.setTimeout(function(){
form.submit();
window.setTimeout(function(){form.remove();}, 0);
},0);
};
var setPopups = function(button, no_one_time_check) {
if (typeof no_one_time_check == "undefined")
no_one_time_check = false;
var tab_url = checkUrl(button.attr("data-tab-url"));
if (tab_url == "none")
tab_url = "";
if ( initOpenModal || !button.is(button_class3)) {
var popup_url = checkUrl(button.attr("data-popup-url"));
{ //check no show
var id = button.attr("data-popup-id");
var cn = "button-" + id + "-nopopup";
}
var popup_url_data_go = checkUrl(button.attr("data-popup-url-go"));
var data = {};
if (popup_url_data_go) {
data = {'go' : popup_url_data_go};
}
}
if (!initOpenModal) {
var tab_url_data_go = checkUrl(button.attr("data-tab-url-go"));
tryOpenTab2(button, tab_url,tab_url_data_go);
}
};
$(document).ready(function(){
var id = 0;
$(button_class1 + "," + button_class3).each(function() {
$(this).attr("data-popup-id", id++);
});
$(button_class1).each(function() {
var button = $(this);
button.on('click.popup-button', function() {
setPopups(button);
return false;
});
});
});
})(jQuery);