2012-03-29 58 views
1
下面

見代碼:我想第1頁提醒「#testing」 ......window.location.hash不會在IE IFRAME警報

這個工作在C和FF但不是在IE:S

第1頁:

這是將要訪問

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8" /> 
</head> 
<body> 
<iframe src="http://page2.com/#testing"></iframe> 
</body> 
</html> 

第2頁頁:

這是iframe的頁面。

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8" /> 
</head> 
<body> 
<script> 
alert(window.location.hash); 
</script> 
</body> 
</html> 
+0

爲什麼你不試試jQuery? – 2012-03-29 09:32:30

+0

我想用簡單的javascript來做... – user1087110 2012-03-29 09:34:47

+1

@MaziarBouali你可以用jQuery發佈解決方案嗎? – 2012-03-29 09:50:02

回答

0

嘗試在IE

+0

不適用於我:S – user1087110 2012-03-29 09:35:51

+0

IE顯示任何錯誤信息或不是? – 2012-03-29 09:47:34

+0

不,沒有錯誤消息。甚至有一個警告框,但它沒有文字... – user1087110 2012-03-29 10:18:19

2

使用window.frameElement.contentWindow.location.hash我確認的問題!如果頁面位於IE9中的跨域iframe中(未在舊版本中測試過),則location.hashwindow.location.hash只是空的!