有没有办法使用 JavaScript 在 Safari 扩展中打开选项卡?

问题描述 投票:0回答:2

我正在尝试使用 JavaScript 打开一个新选项卡。它不起作用,我收到错误:

[Error] SyntaxError: Unexpected token ':'. Expected ')' to end an argument list.
    (anonymous function)

这是我的代码:

function openTab() {
    let myUrl = URL(string: "https://google.com")


    // This grabs the active window.
    SFSafariApplication.getActiveWindow { (activeWindow) in

        // Request a new tab on the active window, with the URL we want.
        activeWindow?.openTab(with: myUrl, makeActiveIfPossible: true, completionHandler: {_ in
        })
    }
}

openTab();

谢谢!

javascript safari
2个回答
0
投票

语法错误。您忘记了第二行对象中的大括号。 应该是

URL({ string: "https:your.url" });

代替:

URL(string: "https:your.url");

0
投票

它不起作用,我尝试使用大括号仍然不起作用

函数 openTab() { 让 myUrl = URL({string: "https://google.com"})

// This grabs the active window.
SFSafariApplication.getActiveWindow { (activeWindow) in

    // Request a new tab on the active window, with the URL we want.
    activeWindow?.openTab(with: myUrl, makeActiveIfPossible: true, completionHandler: {_ in
    })
}
© www.soinside.com 2019 - 2024. All rights reserved.