在 safari 扩展中,表单 onsubmit 不起作用

发布于 2024-09-24 02:21:15 字数 750 浏览 1 评论 0原文

好吧,现在我对正在发生的事情感到非常困惑。我正在创建一个名为 unibar 的 safari 扩展(这是一个单独的工具栏扩展,而不是工具栏项),它是 Chrome 地址栏的克隆。到目前为止我想要的是至少创建一个常规地址栏,并从那里开始构建。这是我的 bar.html 文件,它连接到工具栏。

<html>
    <head>
        <title>Unibar</title>
        <script type="text/javascript">
            function openInTab(source){
                safari.application.activeBrowserWindow.activeTab.url=source;
                }
        </script>
    </head>
    <body>
        <form name="form" onsubmit="javascript:openInTab(server+'safari/');">
            <input type="text" name="textfield" />
        </form>
    </body>
</html>

当我输入地址后按回车键时,它会在浏览器窗口中显示 BAR.HTML!!!!怎么了?!?

Alright, now I am downright bewildered on what is happening. I am creating a safari extension called unibar(which is a separate toolbar extension, not a toolbar item), a clone of Chrome's address bar. what I want so far is to at least create a regular address bar, and build from there. Here is my bar.html file, which is connected to the toolbar.

<html>
    <head>
        <title>Unibar</title>
        <script type="text/javascript">
            function openInTab(source){
                safari.application.activeBrowserWindow.activeTab.url=source;
                }
        </script>
    </head>
    <body>
        <form name="form" onsubmit="javascript:openInTab(server+'safari/');">
            <input type="text" name="textfield" />
        </form>
    </body>
</html>

When I hit enter after I have typed in my address, IT BRINGS UP BAR.HTML IN THE BROWSER WINDOW!!!! What is happening?!?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞别 2024-10-01 02:21:15

删除 javascript: 并添加 return false;

Remove javascript: and add return false;.

心清如水 2024-10-01 02:21:15

啊!我已经找到答案了。我愚蠢地忘记在代码中声明什么是“服务器”。这是我的新代码。

<html>
<head>
    <title>Unibar</title>

    <script type="text/javascript">
    function openInTab(source){
        safari.application.activeBrowserWindow.activeTab.url=source;
        }
    </script>

</head>
<body>
<form name="form">
<input type="text" name="textfield" />
<input type="button" value="Go!" onclick="javascript:openInTab(document.form.textfield.value);" />
</form>
</body>
</html>

Ah! I have found the answer. I idiotically forgot to declare what "server" is in the code. Here is my new code.

<html>
<head>
    <title>Unibar</title>

    <script type="text/javascript">
    function openInTab(source){
        safari.application.activeBrowserWindow.activeTab.url=source;
        }
    </script>

</head>
<body>
<form name="form">
<input type="text" name="textfield" />
<input type="button" value="Go!" onclick="javascript:openInTab(document.form.textfield.value);" />
</form>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文