문제

우리는 다음과 같이 보이는 HTML이 있습니다.

<form id="MyUserControl" runat="server" method="post">
   <script language="javascript" src="javascript.js"></script>

JavaScript 파일에는 다음과 같은 내용이 포함되어 있습니다.

document.write('<object id="MyUserControl" ');
document.write('classid="MyUserControl.dll#MyNamespace.MyUserControl"');
document.write('height="611" width="951" >');
document.write('<param name="Parm1" value="' + parm1 + '" />');
document.write('</object>');

기본적으로 객체가 제대로로드되지 않으면 텍스트를 표시하거나 대기 텍스트를 제자리에두고 싶습니다.

이 모든 이유는 오래된 앱을 FoxPro에서 .NET으로 마이그레이션하는 동안 여전히 사용 중이기 때문입니다. 상당히 큰 응용 프로그램이며 한 번에 화면을 변환하고 있습니다. 우리는 .NET 사용자 컨트롤을 구축하고 있으며 FoxPro 내부의 브라우저 객체에 표시됩니다. 위의 HTML 및 JS를 사용하면 웹 페이지에 WinForms 사용자 컨트롤을 포함시킬 수 있습니다.

특정 사용자가 응용 프로그램 서버 설정에 대한 코드 액세스 그룹이없는 경우 사용자 컨트롤이 렌더링되지 않으며 화면은로드하려는 것처럼 보이는 것처럼 보이는 왼쪽 상단에 작은 아이콘을 표시합니다. 로드되지는 않지만 사용자가 팀에게 이메일을 보내 액세스를 직접 알리도록 신호를 보내고 싶습니다.

나는 대기와 alt를 사용하려고 시도했지만 텍스트를 보여주지 않았습니다. 모든 사용자는 IE7을 가지고 있으며 이는 임시 솔루션 (<6 개월) 일뿐입니다.

도움이 되었습니까?

해결책

객체 태그에 인라인 요소를 넣을 수 있으며로드하지 않으면 사용자에게 제시됩니다.

<object>
  This object failed to load,
  try to install <a href="http://plugin-site/">here</a>
</object>

MSDN : 객체 요소 | 객체 객체

이상한 행동에 대한 메모를 추가하고 싶었습니다. (예 : <8) 실패 내용이 표시되는 위의 코드를 사용하면 DOM의 객체에 대한 액세스를 잃게됩니다. 따라서 비어 있고 부하 성공을 결정하기 위해 추가 코드를 수행 할 수 있습니다.

<!DOCTYPE html>
<html>
<head>
  <title>so-objects</title>
  <script type="text/javascript">

    function add(text) {
      document.body.appendChild(document.createElement("div"))
                   .appendChild(document.createTextNode(text));
    };

    function each(o, f, c) {
      for (var i=0, l=o.length; i<l; i++) f.call(c, o[i], i, o);
    };

    onload = function() {

      // IE returns null and has mysteriously removed the object from DOM
      add("byId = "+ document.getElementById("no-access") );

      // IE returns 2 instead of 3
      add("byTags = "+ document.getElementsByTagName("object").length );

      // verify successful load if the object property is available
      each(document.getElementsByTagName("object"), function(node) {
        add(node.id +" = "+ !!node.object);
      });

    };

  </script>
  <style type="text/css">
    object, span { position: absolute; left:-10000px; }
  </style>
</head>
<body>

  <object id="access">
  </object>

  <object id="no-access">
    <span>failed</span>
  </object>

  <object id="supported"
     classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6">
  </object>

</body>
</html>

반환 된 값 IE <8

byId = null
byTags = 2
access = false
supported = true

반환 된 값 W3C 준수

byId = [object HTMLObjectElement]
byTags = 3
access = false
no-access = false
supported = false

직접 시도하십시오

다른 팁

당신의 상황에 더 구체적인 다른 답변을 추가합니다.

JavaScript를 변경하면 원하는 결과가 발생할 수 있습니다 (페이지에 적용되는이 개체의 한 인스턴스 만있는 경우).

function onchange(o) {
  if (o.readyState == 4) {
    if (o.object == null) {
      alert("UserControl is not installed, please email your administrator.");
      // or, toggle display of a message dialog in HTML
      //document.getElementById("not-installed").style.display = "block";
    }
  }
};

document.write('<object id="MyUserControl"');
document.write(' classid="MyUserControl.dll#MyNamespace.MyUserControl"');
document.write(' height="611" width="951" onreadystatechange="onchange(this)">');
document.write(' <param name="Parm1" value="' + parm1 + '" />');
document.write('</object>');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top