创建一个不会被阻止的书签

发布于 2024-09-08 02:45:49 字数 1288 浏览 5 评论 0原文

目标:创建一个调用远程 JavaScript 文件以打开弹出窗口的小书签。弹出窗口的功能与 Delicious 的书签功能类似。

背景:目前,我在这个 javascript 文件中使用 window.open,但是几乎所有主流浏览器都会阻止弹出窗口。

替代解决方案与 Delicious 编写其 bookmarklet 的方式非常相似 - 通过 bookmarklet 本身内的 javascript 查询调用 window.open。但是,我需要将来能够修改 javascript 文件的其他内容,而不需要用户不断获取最新版本的书签。

我确定要发生的事情:由于 window.open 调用不是由于用户点击而直接发生的,所以浏览器认为这是应该被阻止。这是关于此的来源

是我的教程最近在创建对远程 js 文件的调用时引用。

这是我的代码正在执行的操作的基本示例; window.open/popup 部分是我要包含的唯一重要部分,因为它是我认为导致复杂化的唯一部分:

远程 javascript 文件的示例:

if (typeof jQuery == 'undefined') {
    var jQ = document.createElement('script');
    jQ.type = 'text/javascript';
    jQ.onload=runthis;
    jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
    document.body.appendChild(jQ);
} else {
    runthis();
}

function runthis() {
    window.open('http://www.google.com/', 'a title',
       'location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550');
}

我真的很感激任何帮助,因为这一直困扰着我尽管!

Goal: To create a bookmarklet that calls a remote javascript file that opens a popup window. The popup window is functionally similar to what Delicious's bookmarklet does.

Background: Currently, I'm using window.open within this javascript file, however the popup is getting blocked by pretty much every major browser.

The alternative solution to this is very similar to the way Delicious wrote their bookmarklet - calling window.open through a javascript query within the bookmarklet itself. However, I need the ability to modify the other contents of my javascript file in the future without requiring users to continually grab newest releases of the bookmarklet.

What I've determined to be happening: Since the window.open call is not occurring directly as a result of a click by the user, the browser feels this is something that should be blocked. Here's a source on this.

This is the tutorial I referenced most recently in creating the call to the remote js file.

Here is a basic example of what my code is doing; the window.open/popup portion is the only significant part I'm including as it's the only part I feel is causing the complication:

Example of the remote javascript file:

if (typeof jQuery == 'undefined') {
    var jQ = document.createElement('script');
    jQ.type = 'text/javascript';
    jQ.onload=runthis;
    jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
    document.body.appendChild(jQ);
} else {
    runthis();
}

function runthis() {
    window.open('http://www.google.com/', 'a title',
       'location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550');
}

I'd really appreciate any help as this has been stumping me for a while!

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

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

发布评论

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

评论(1

风蛊 2024-09-15 02:45:49

一种看起来更好并回避阻塞问题的方法是让小书签在用户当前正在查看的页面中插入 iframe。当我问这个问题时,最终又采取了这种方法。效果很好。

An approach that looks better and side-steps the blocking issue is to have the bookmarklet insert an iframe in the page the user is currently viewing. Ended up taking this approach back when I asked this question. Worked out fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文