简体   繁体   中英

JS window.open method in Safari browser

I've faced a problem with JS window.open method in Safari browser:

The standard window.open() JavaScript method cannot be used to open a new tab and window from a global HTML file or an extension bar. https://developer.apple.com/library/archive/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html

So, I'm trying this code instead:

safari.self.browserWindow.openTab(myLink);

But I get an error:

index.html:199 Uncaught ReferenceError: safari is not defined

(in google chrome developer tools iPhone emulations, it doesn't work on real iPhones either)

Edit, here is more context:

var link = 'http://www.example.com/';
something.addEventListener("touchend", function (e) {
    e.preventDefault();
    e.stopPropagation();
    if(navigator.userAgent) {
        safari.self.browserWindow.openTab(link);
    }
});

Why safari.self.browserWindow.openTab(myLink); doesn't work in Safari?

Use Like this: safari.self.tab.dispatchMessage('openurlNewTab', ' http://www.example.com/ ');

//the message name 'openurlNewTab' is arbitrary//

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM