我正在尝试使用 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();
谢谢!
语法错误。您忘记了第二行对象中的大括号。 应该是
URL({ string: "https:your.url" });
代替:
URL(string: "https:your.url");
它不起作用,我尝试使用大括号仍然不起作用
函数 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
})
}