用 Greasemonkey 替换对象参数的值
你好 :) 我试图用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不知道任何
getElementsByName
函数。也许这是 GreaseMonkey 的一个功能。但在JS中我会做类似的事情:编辑:抱歉我的无知,
getElementsByName
存在并返回和类似数组的getElementsByTagName
。所以代码将是:Don't known of any
getElementsByName
function. Maybe it's a GreaseMonkey function. But in JS I would do something like:EDIT: Sorry about my ignorance,
getElementsByName
exists and return and array-like asgetElementsByTagName
. So the code will be:getElementsByName 是 document 的成员并返回一个数组(我最好说“类似数组的 DOMNodeList”)。
所以你应该使用:
getElementsByName is a member of document and returns an array(I should better say "an array-like DOMNodeList").
So you should use:
更改
allowFullScreen
值可能还不够,因为 Flash 对象已经使用旧值进行了初始化。要解决此问题,请从一开始就使用新的
allowFullScreen
值创建一个新的 Flash 对象。以下代码应该可以工作,但它需要 jQuery,因此:
(1) 将此行添加到 Greasemonkey 元数据部分,就在
// @include
指令之后:(2) 使用 GM 的 " “管理用户脚本”面板,卸载然后重新安装 Greasemonkey 脚本,以确保 jQuery 文件复制到您的 PC。
(3) 然后试试这段代码:
(假设
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):(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:
(Assumes that the
object
id isflashc
as shown in the question.)