|
|
|
|
|
iframe地址我想做成這樣:
<iframe src="http://anydomain.com/frame.php?ref=http://currentpageurl.com/dir"></iframe>
于是我使用這樣的寫法:
<iframe src="http://localhost/<script type="text/javascript">document.write(window.location.pathname);</script>.html" frameborder="0" scrolling="no" onload="resizeIframe(this)" />
但是并沒有達(dá)到我想要的效果,卻提示錯(cuò)誤了:
從客戶端(<)中檢測到有潛在危險(xiǎn)的 Request.Path 值。:
地址: http://localhost/%3Cscript%20type=
可以知道,iframe地址直接用 document.write
輸出是不行的。
那么該如何實(shí)現(xiàn)我原先的想法呢?
其實(shí)還是用JS或JQuery來實(shí)現(xiàn),只不過寫法跟我上面的寫法有所不同。下面介紹用最簡單的JS來實(shí)現(xiàn),代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iframe src賦值的方法</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<iframe frameborder="1" id="barframe" ></iframe>
</body>
</html>
<script type="text/javascript">
document.getElementById("barframe").src = "http://anydomain.com/frame.php?ref=http://localhost/" + window.location.pathname;
</script>
代碼分析,先輸出iframe的html,再用JS給iframe的src賦值。