用 Greasemonkey 替换对象参数的值

发布于 2024-10-07 20:08:40 字数 728 浏览 3 评论 0原文

你好 :) 我试图用 Greasemoneky 操作一些对象,所以我必须编写一个脚本:) 我想更改allowFullScreen参数的一个值。

<object width="760" height="660" type="application/x-shockwave-flash" id="flashc" name="flashc" data="http://example.com/swf/39.swf">
  <param name="menu" value="false">
  <param name="allowFullScreen" value="false"> // I want to change this to **"true"**
  <param name="scale" value="noscale">
  <param name="wmode" value="transparent">
  <param name="allowScriptAccess" value="always"> 
</object>

我已经写了一些东西,但它不起作用:

function allowFS()
{ 
    var obj = getElementsByName("allowFullScreen")
    obj.setAttribute("value", "true");

}

对不起我的语言

Hello :)
I trying to manipulate with some object with Greasemoneky so i have to write a script :)
I want to change one value of allowFullScreen param.

<object width="760" height="660" type="application/x-shockwave-flash" id="flashc" name="flashc" data="http://example.com/swf/39.swf">
  <param name="menu" value="false">
  <param name="allowFullScreen" value="false"> // I want to change this to **"true"**
  <param name="scale" value="noscale">
  <param name="wmode" value="transparent">
  <param name="allowScriptAccess" value="always"> 
</object>

I already written something but it doesn't work:

function allowFS()
{ 
    var obj = getElementsByName("allowFullScreen")
    obj.setAttribute("value", "true");

}

Sorry for my language

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

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

发布评论

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

评论(3

∞琼窗梦回ˉ 2024-10-14 20:08:40

不知道任何 getElementsByName 函数。也许这是 GreaseMonkey 的一个功能。但在JS中我会做类似的事情:

var params = document.getElementsByTagName('param');

for ( var i = 0; i < params.length; i++ )
{
    if ( params[i].name == 'allowFullScreen' )
    {
        params[i].setAttribute('value', 'true');
    }
}

编辑:抱歉我的无知,getElementsByName存在并返回和类似数组的getElementsByTagName。所以代码将是:

var params = document.getElementsByName('allowFullScreen');

for ( var i = 0; i < params.length; i++ )
{
    params[i].setAttribute('value', 'true');
}

Don't known of any getElementsByName function. Maybe it's a GreaseMonkey function. But in JS I would do something like:

var params = document.getElementsByTagName('param');

for ( var i = 0; i < params.length; i++ )
{
    if ( params[i].name == 'allowFullScreen' )
    {
        params[i].setAttribute('value', 'true');
    }
}

EDIT: Sorry about my ignorance, getElementsByName exists and return and array-like as getElementsByTagName. So the code will be:

var params = document.getElementsByName('allowFullScreen');

for ( var i = 0; i < params.length; i++ )
{
    params[i].setAttribute('value', 'true');
}
鱼忆七猫命九 2024-10-14 20:08:40

getElementsByName 是 document 的成员并返回一个数组(我最好说“类似数组的 DOMNodeList”)。

所以你应该使用:

var obj = document.getElementsByName("allowFullScreen")[0];

getElementsByName is a member of document and returns an array(I should better say "an array-like DOMNodeList").

So you should use:

var obj = document.getElementsByName("allowFullScreen")[0];
悲念泪 2024-10-14 20:08:40

更改 allowFullScreen 值可能还不够,因为 Flash 对象已经使用旧值进行了初始化。

要解决此问题,请从一开始就使用新的 allowFullScreen 值创建一个新的 Flash 对象。

以下代码应该可以工作,但它需要 jQuery,因此:

(1) 将此行添加到 Greasemonkey 元数据部分,就在 // @include 指令之后:

// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js

(2) 使用 GM 的 " “管理用户脚本”面板,卸载然后重新安装 Greasemonkey 脚本,以确保 jQuery 文件复制到您的 PC。

(3) 然后试试这段代码:

$('#flashc param[name="allowFullScreen"]').val ("true");
var jNewFlash = $('#flashc').clone (true);
$('#flashc').replaceWith (jNewFlash)

(假设object id是flashc,如问题所示。)

It's probably not enough to alter the allowFullScreen value, because the flash object will have already been initialized with the old value.

To get around this, create a new flash object using the new allowFullScreen value from the start.

The following code should work, but it requires jQuery, so:

(1) Add this line to the Greasemonkey metadata section, just after the // @include directive(s):

// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js

(2) Using GM's "Manage User Scripts" panel, Uninstall and then reinstall the Greasemonkey script to ensure that the jQuery file is copied to your PC.

(3) Then try this code:

$('#flashc param[name="allowFullScreen"]').val ("true");
var jNewFlash = $('#flashc').clone (true);
$('#flashc').replaceWith (jNewFlash)

(Assumes that the object id is flashc as shown in the question.)

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