簡體   English   中英

有沒有辦法使用 javascript 在 Safari 擴展中打開選項卡?

[英]Is there a way to open a tab in a Safari extension using javascript?

我正在嘗試使用 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();

謝謝!

語法錯誤。 您忘記了第二行 object 中的大括號。 它應該是

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

代替:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM