我有以下问题..这个脚本在Windows上的chrome / mozilla等工作,但在safari iOS中没有。 JS已激活。
<script>
function openWindow(select) {
var value = select.options[select.selectedIndex].value;
window.open(value, 'newwindow')
}
</script>
我该怎么办,错误在哪里?谢谢你的帮助
答案 0 :(得分:0)
看起来window.open无法在iPhone / iPad上运行。
您需要创建一个链接,并在您的代码中创建该链接上的点击事件。
以下是代码:
function openTab(url) {
// Create link in memory
var a = window.document.createElement("a");
a.target = '_blank';
a.href = url;
// Dispatch fake click
var e = window.document.createEvent("MouseEvents");
e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
};
openTab('http://www.google.com'); // will open new tab on iPad and new window on iPhone
我得到了答案here。