1

我想在 .aspx 页面中显示 iframe,并且 iframe 源应该是同一页面。

我需要使用相对 uri。

我应该赋予“src”属性什么值?

我意识到这有点不寻常——页面将根据传入的参数以不同的状态显示,因此 iframe 不会在其自身中显示。

4

3 回答 3

3

如果你这样做,你会得到一个无限循环......进程将“永远不会结束”。也许这就是为什么它是白色的?它真的在处理页面.. - 那是你想要的吗?例如,如果您只想要 2-3 页的深度,您可以使用查询字符串,例如当查询字符串增加到 3 时禁用 iframe。 MyPage.aspx?depth=1 --MyPage.aspx?depth=2 --MyPage .aspx?depth=3 等

于 2009-02-25T06:10:32.637 回答
2

文字相对路径应该有效。即:MyPage.aspx

这是一个 ASP.NET 示例...

似乎对我来说很好用以下......

标记:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <iframe runat="server" id="myFrame" src="Default.aspx?message=Hello%20World"></iframe>
    <div id="myDiv" runat="server"></div>
    </div>
    </form>
</body>
</html>

代码背后:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string message = Request.QueryString["message"];
            if (null != message)
            {
                myDiv.InnerText = message;
                myFrame.Visible = false;
            }
            else
            {
                myDiv.Visible = false;
            }
        }
    }
}
于 2009-02-25T06:00:43.580 回答
1

简短的回答是 iframe 标记中的 src="localfilename.aspx" 。宽松应用的网络标准说,任何没有以“/”开头的内容都是相对于当前页面的位置。有时 src="" 甚至可以用于替换当前文件名(在浏览器级别)

于 2009-02-25T06:57:51.447 回答