0
我在JavaScript中編碼,我知道它不是一個整潔的解決方案。Iframe源更改後重定向用戶?
這是我的代碼。我正在使用溢出iframe。我希望用戶在iframe源代碼更改後重定向。但是我的代碼在iframe源代碼更改後沒有重定向用戶。
請注意:我想將iframe放置在頁面上我想檢查iframe中鏈接的歷史記錄,以檢測iframe源文件更改而不是頁面源更改。我無法控制iframe的內容。它是一個跨域的iframe。例如 http://freestarbucksgiftcard4u.blogspot.in/2012/04/stalk-overflow-testing.html
此外,iframe中的鏈接是隨機的,所以我無法確定。我可以將它與歷史進行比較以檢測變化。
的iframe代碼:
<div class="offerlink"
style="overflow: hidden; width: 467px; height: 321px; position: relative;" id="i_div"><iframe name="i_frame" src="http://www.villanovau.com/form/pm/070809_vu_pm_save/?source=193664zv1&utm_source=Quigo&utm_medium=PPC&utm_campaign=VU_PM&WT.mc_id=4321" style="border: 0pt none ; left: -518px; top: -274px; position: absolute; width: 1242px; height: 616px;" scrolling="no"></iframe></div>
Javscript代碼:
var Delay = 0;
var AppearDelay = 10;
var oldHistLength = history.length;
var once_per_session=1;
var unknown=true;
function setcookie() {
if (unknown==false){
document.cookie="alerted=yes"
}
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
setInterval ("checkHistory()", 1000);
function checkHistory()
{
if (oldHistLength != history.length)
{
redirect();
oldHistLength = history.length;
}
}
$(document).ready(function()
{
$('.offerlink').click(function()
{
setTimeout('redirect()', Delay*1000);
});
});
這個解決方案不是爲我工作。請幫我調試這個javascript。
編輯的問題,請做一些其他的解決方案。 – 2012-04-27 15:08:18
首先,setInterval使用函數引用來執行。像這樣http://jsfiddle.net/BwmSB/ – 2012-04-27 15:20:44
Allso,爲什麼所有的cookie都是?你需要堅持多頁嗎?或單個頁面? – 2012-04-27 15:21:50