通过点击更改两个网页之间两个iframe的内容相同点击

问题描述:

我需要通过点击更改两个网页之间两个iframe的相同内容。就像一个幻灯片,您只需点击一下,就可以在两个屏幕上切换到新的幻灯片。通过点击更改两个网页之间两个iframe的内容相同点击

我希望你能给我答案! 谢谢!

如果您熟悉更改一个iframe的内容,那么在多个iframe上执行该操作相当简单。如果你确信你将永远不会需要改变两个以上的I帧,那么最简单的解决办法是这样做的JavaScript:

// function that updates a single iframe 
function updateIframe(iframe) { 
    var iframeDocument = iframe.contentWindow.document; 
    // iframeDocument is the iframe's document, so commands 
    // like the ones below will work. 
    // iframeDocument.appendChild(); 
    // iframeDocument.body.innerHTML = "<h1>Hello World</h1>"; 
} 

// get the iframes from the DOM by their html id attribute 
var iframe1 = document.getElementById('iframe1'); 
var iframe2 = document.getElementById('iframe2'); 

// bind a click event listener to the document body that 
// will run updateIframe on both iframes 
document.body.addEventListener('click', function() { 
    updateIframe(iframe1); 
    updateIframe(iframe2); 
}); 
+0

请问该解决方案的工作时,它的网页间? – 2014-11-06 08:38:14

+0

当我读到你的问题时,我认为你的意思是你在一个网页上有两个不同的网页加载到iframe中。如果您正在寻找网页上下文以外的网页来更改网页,那么您需要某种操作系统宏或应用程序扩展。 – macguru2000 2014-11-07 23:15:55