这是我的情况:我有一个页面,其中包含一个经常更新的横幅,这意味着每次更新页面(不能覆盖)时横幅的图像路径都会有所不同。无论如何,它将位于具有常量名称的div或容器内。
我需要做的是检索该图像路径并将其打印在不同的页面中,因此如果第一页中的横幅发生变化,它将在第二页中自动更改。
我想也许有些javascript可以完成这项工作,但我不确定如何从div中获取图像路径。
任何帮助将不胜感激,阿根廷的问候
答案 0 :(得分:0)
使用html5和javascript的解决方案就是这个
you can get the image tag through javascript(as u say it is in div
and whose id you know)
something like
src = document.getElementById("id").childnodes[0].src
should work for u
then you can store this src in the localStorage
localStorage["src"] = src;
as soon as you store something in localstorage it will fire a
"storage" event in all the other pages except the page in which
you have actually stored the src
so handle "storage" event in the other pages like this
window.addEventListener("storage",func,false);
function func(event)
{
src = localStorage[event.key];
//now src has the updated src :)
}