开发者

How do I "trigger" the external script file loaded from a bookmarklet

开发者 https://www.devze.com 2023-02-06 12:54 出处:网络
I successfully loaded a script into an existing page by bookmarklet. (Can tell my a success js request seen in firebug)

I successfully loaded a script into an existing page by bookmarklet. (Can tell my a success js request seen in firebug) The next step is to make the script run.

This is what my external script looks like.

javascript: (function (开发者_如何学运维) {
    alert('hello world');
}

and I don't see the alert. Missing something?


The function is not called and you have a syntax error (missing closing bracket )). You can make it an immediate executed function:

javascript: (function () {
    alert('hello world');
}())

Update: If you are actually injecting a script tag into the head via the bookmarklet, then you don't need to have javascript: in the file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号