我想用我自己的代碼,在http://wtikay.com/和各種其他地方看到的歷史嗅探演示覆制。 (這是一個很長的故事。)複製wtikay - IE瀏覽器 - currentStyle不更新時,它應該
我有一些在大多數老版本的瀏覽器(最新的Safari和Chrome版本和Firefox 4 beta版都有防禦功能)可靠地工作 - 但它在IE7或8(haven'試着6),我不明白爲什麼。這似乎是,IE只是不打擾更新其渲染,當我改變a
元素href
財產 - 但據我所知,這正是wtikay所做的,它的工作原理。
測試文件:
<!doctype html>
<html><head>
<title>gevalt</title>
<style>
body { background-color: gray }
a:link { text-decoration: none; color: black }
a:visited { color: white }
</style>
<body>
<span id="container"><a href="" id="testlink">test</a></span>
<a href="ftp://">minus</a>
<a href="http://www.google.com/">plus</a>
<script>
window.onload = function()
{
var testlink = document.getElementById("testlink");
var results = document.getElementById("results");
var container = document.getElementById("container");
var report = "";
testlink.href = "ftp://";
container.removeChild(testlink);
container.appendChild(testlink);
report += " -" + (testlink.currentStyle || window.getComputedStyle(testlink, "")).color;
testlink.href = "http://www.google.com/";
container.removeChild(testlink);
container.appendChild(testlink);
report += " +" + (testlink.currentStyle || window.getComputedStyle(testlink, "")).color;
results.appendChild(document.createTextNode(report));
};
</script>
<pre id="results">
</pre>
</body></html>
在它的作品中,「測試」和「加」將是白色的(假設你已經在瀏覽器中訪問www.google.com),字瀏覽器「減號」將是黑色的,它將在下面打印類似「-rgb(0,0,0) +rgb(255,255,255)
」的內容。在IE中,「測試」將是黑色而不是白色,並且在它下面將顯示「-black +black
」。或者可能「測試」將是白色的,但在它下面將顯示「-white +white
」。這兩個都是失敗的。
任何幫助將不勝感激。