Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript将查询参数更新为Flash对象_Javascript_Html_Dom - Fatal编程技术网

使用JavaScript将查询参数更新为Flash对象

使用JavaScript将查询参数更新为Flash对象,javascript,html,dom,Javascript,Html,Dom,我为Flash嵌入了以下简单对象: <object id="siwp_obj" type="application/x-shockwave-flash" data="button.swf?file=%2F/ex.php?id=89804c7326e92a00c5c88c181190af8159cf060b" height="32" width="32"> <param id="siwp_param" name="movi

我为Flash嵌入了以下简单对象:

<object id="siwp_obj"
        type="application/x-shockwave-flash" 
        data="button.swf?file=%2F/ex.php?id=89804c7326e92a00c5c88c181190af8159cf060b"
        height="32" width="32">
    <param id="siwp_param" name="movie"
           value="button.swf?file=%2F/ex.php?id=89804c7326e92a00c5c88c181190af8159cf060b" />
</object>
我试图假设没有可用的javascript库,因为它将在插件系统中使用

有没有人知道如何动态更新对象和参数标记的URL

编辑:

在Chrome中,我做了一些调试,注意到参数正在更新,但是当我与flash交互时,它没有被重新加载

例如:

var obj = document.getElementById('siwp_obj');
alert(obj.getAttribute('data')); // the old URL with old ID
obj.setAttribute('data', obj.getAttribute('data').replace(/[a-zA-Z0-9]{40}$/, cid));
alert(obj.getAttribute('data')); // the new URL with new ID

…但是,当我单击flash对象尝试从新URL流式传输时,它仍然引用具有旧ID的旧URL。因此DOM正在更新,但浏览器随后忽略了对象的某些参数已更改的事实。有什么想法吗?

我认为最好是动态创建整个元素(而不是在加载到页面后将其作为getElementById()处理)


因此,
document.createElement(“object”);
以及
document.createElement(“param”)
然后添加所有属性,然后
appendChild()
将其添加到某个父节点……我相信这应该可以工作(尽管我还没有测试它).

我可以通过更新dom元素,然后创建一个克隆并在文档中替换它来让它工作

这适用于IE6+、Firefox和Chrome(尚未在任何其他浏览器中测试)


如果在cid赋值周围添加引号会怎么样?
var cid=“”
这只是一个例子,但它是一个引号内的字符串。我对它进行了更新,以减少混淆。你可以使用jquery吗?。然后我认为它很简单。@BibinVelayudhan最好不要,因为它将在许多网站上使用,其中一些网站将不会安装任何JS库。此外,我更希望不必替换整个标记,只替换一小部分。
var obj = document.getElementById('siwp_obj');
alert(obj.getAttribute('data')); // the old URL with old ID
obj.setAttribute('data', obj.getAttribute('data').replace(/[a-zA-Z0-9]{40}$/, cid));
alert(obj.getAttribute('data')); // the new URL with new ID
// update object and param tag with new id
var obj = document.getElementById('siwp_obj');
obj.setAttribute('data', obj.getAttribute('data').replace(/[a-zA-Z0-9]{40}$/, cid));
var par = document.getElementById('siwp_param'); // this was a comment...
par.value = par.value.replace(/[a-zA-Z0-9]{40}$/, cid);

// replace old flash w/ new one using new id
// clone the original object tag and then insert the clone, remove the original
var newObj = obj.cloneNode(true);
obj.parentNode.insertBefore(newObj, obj);
obj.parentNode.removeChild(obj);