【问题标题】:Asp.net - Javascript does not work on an iframe containing MVC viewAsp.net - Javascript 不适用于包含 MVC 视图的 iframe
【发布时间】:2015-09-22 16:54:23
【问题描述】:

我创建了一个视图来在 iframe 中显示“qlikview”文档。当从控制器调用提到的视图时,iframe 会阻止任何 javascript 执行。如果我删除 iframe js 工作正常。

iframe 工作正常,但 js 不行。这是什么原因?

谢谢。

我的观点:

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div>
    <iframe id="qlikFrame" src="@ViewBag.IframeLink" style="width:100%; height:768px" frameborder="0" scrolling="no" />
</div>

_布局:

 $(document).ready(function() {

   alert("you clicked the paragraph");
 });
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>@ViewBag.Title - My ASP.NET Application</title>
  @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr")

</head>

<body>
  <div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        @Html.ActionLink("Home", "Index", "Home", null, new { @class = "navbar-brand" })
      </div>
      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
          <li>@Html.ActionLink("Home", "Index", "Home")</li>
          @if (@Request.IsAuthenticated) {
          <li class="dropdown">
            <a href="#" id="dropdown-item" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                Dashboards
                                <span class="caret"></span>
                            </a>
            <ul class="dropdown-menu">
              <li>@Html.ActionLink("SD", "Document", "Dashboard", new { Id = SD" }, null)</li>
              } @if (Request.IsAuthenticated && User.IsInRole("Admin")) {
              <li>@Html.ActionLink("RolesAdmin", "Index", "RolesAdmin")</li>
              <li>@Html.ActionLink("UsersAdmin", "Index", "UsersAdmin")</li>
              }
            </ul>
            @Html.Partial("_LoginPartial")
      </div>
    </div>
  </div>

  <div class="container body-content">
    @RenderBody()
    <hr />
  </div>

  @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/bootstrap") @RenderSection("scripts", required: false)

</body>
</html>

【问题讨论】:

    标签: asp.net asp.net-mvc iframe qlikview


    【解决方案1】:

    这是由于 vs2015 或 MVC 的一种奇怪行为,不确定是哪一个。

    问题在于 iframe 闭包标签:

    如果我写&lt;iframe&gt;&lt;/iframe&gt; Js 有效,但如果我写&lt;iframe /&gt; Js 无效。

    在 vwd2010 的一个 webform 项目中,我使用了后一种语法,iframe 和 Js 工作没有任何问题。 如果有人遇到这种不当行为,以上可能是解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-01
      • 2016-12-23
      • 2011-01-08
      相关资源
      最近更新 更多