Browse Source

infusing "<script language="javascript"></script>" tag if such was not specified on the page

Arkady Trestman 16 years ago
parent
commit
b83063a53b
1 changed files with 40 additions and 0 deletions
  1. 40 0
      direct/src/plugin_activex/P3DActiveXCtrl.cpp

+ 40 - 0
direct/src/plugin_activex/P3DActiveXCtrl.cpp

@@ -308,6 +308,46 @@ int CP3DActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
 
     ::SysFreeString( url );
 
+    CComPtr<IHTMLElementCollection> pHtmlElementCollect;
+    hr = pHtml2Doc->get_scripts( &pHtmlElementCollect );
+    if ( FAILED( hr ) || !pHtmlElementCollect )
+    {
+        return ( error = -1 );
+    }
+    long collectionLength = 0;
+    hr = pHtmlElementCollect->get_length( &collectionLength );
+    if ( FAILED( hr ) || !pHtmlElementCollect )
+    {
+        return ( error = -1 );
+    }
+    if ( collectionLength < 1 )
+    {
+        // javascript engine was not specified on the page.
+        // hence we need to initialize it by infusing javascript 
+        // element tags
+
+        CComPtr<IHTMLElement> spHtmlElement; 
+        hr = pHtml2Doc->createElement( CComBSTR( "script" ), &spHtmlElement );
+        if ( SUCCEEDED( hr ) && spHtmlElement )
+        {
+            hr = spHtmlElement->put_language( CComBSTR( "javascript" ) );
+            if ( SUCCEEDED( hr ) )
+            {
+                CComPtr<IHTMLDOMNode> spElementDomNode;
+                hr = spHtmlElement->QueryInterface( IID_IHTMLDOMNode, ( void** )&spElementDomNode );
+                if ( SUCCEEDED( hr ) && spElementDomNode )
+                {
+                    CComPtr<IHTMLDOMNode> spHtmlDomNode;
+                    hr = pHtml2Doc->QueryInterface( IID_IHTMLDOMNode, ( void** )&spHtmlDomNode );
+                    if ( SUCCEEDED( hr ) && spHtmlDomNode )
+                    {
+                        CComPtr<IHTMLDOMNode> newNode;
+                        hr = spHtmlDomNode->appendChild( spElementDomNode, &newNode );
+                    }
+                }                    
+            }
+        }
+    }
     std::string p3dDllFilename;
     error = m_instance.DownloadP3DComponents( p3dDllFilename );
     if ( !error && !( p3dDllFilename.empty() ) )