技術(shù)頻道導(dǎo)航
HTML/CSS
.NET技術(shù)
IIS技術(shù)
PHP技術(shù)
Js/JQuery
Photoshop
Fireworks
服務(wù)器技術(shù)
操作系統(tǒng)
網(wǎng)站運(yùn)營

贊助商

分類目錄

贊助商

最新文章

搜索

iframe地址賦值失敗的原因

作者:admin    時(shí)間:2018-1-18 15:14:49    瀏覽:

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賦值。

execcodegetcode

您可能對以下文章也感興趣

標(biāo)簽: iframe  frame  
x
  • 站長推薦
/* 左側(cè)顯示文章內(nèi)容目錄 */