javascript - Windows.Forms.WebBrowser loading page with local SVG file -


i have html page generating in c# project. works, when open page in ie.

<!doctype html>  <meta http-equiv='x-ua-compatible' content='ie=10' />  <html lang='en'>  <head>      <title>templatesvg</title>      <script type='text/javascript' src='interfacesvg.js'></script>  </head>  <body style='margin: 0; overflow: hidden;'>      <div class="page-content">          <object id='idsvg'  type='image/svg+xml' data='d:\examples\examplefla.svg'></object>      </div>  </body>  </html>

i loaded getting text in web browser

    if (webbrowser.document == null)     {         webbrowser.documenttext = thehtmltext;     }     else     {         webbrowser.document.opennew(true);         webbrowser.documenttext = thehtmltext;     } 

but file interfacesvg.js isn't find.

when give full path js file src='d:\[path]\interfacesvg.js' js script generate exception on line getsvgdocument().

var svgdoc;  window.addeventlistener('load', function () {        svgdoc = document.getelementbyid("idsvg");      if (svgdoc == null) { alert("error"); return; }      svgdoc = svgdoc.getsvgdocument(); // ie created access deny.  });

edit: try insert text js file.

<script>text interfacesvg.js </scipt>     

but generates same exception (access deny) on line getsvgdocument()

i saved result html page in folder svg file , use function navigateinstead of documenttext. works... don't want write on disk anything.

    string path =  path.getdirectoryname(pathtosvgfile);     string file = "\\"+path.getfilenamewithoutextension(pathtosvgfile);     string newfile = path + file;     file.writealltext(newfile, thehtmltext);     webbrowser.navigate(newfile); 

i found how need open user page.

  1. create template html page without scripts.

<!doctype html>  <meta http-equiv='x-ua-compatible' content='ie=10' />  <html lang='en'>  <head>      <title>empty page</title>  </head>  <body style='margin: 0; overflow: hidden; '>      <div class="page-content">          <object id='idsvg' style='height: 100%; width: 100%;  position:absolute;' type='image/svg+xml' data='{0}'></object>      </div>  </body>  </html>

  1. add script files , change text body of html page need in event webbrowser.navigated.

        static string pathtosvgfile;     public static void opensvg(this webbrowser webbrowser, string pathtosvgfile)     {         if (webbrowser.readystate == webbrowserreadystate.complete || webbrowser.readystate == webbrowserreadystate.uninitialized)         {             webbrowser.navigate([path emptypage.html]);             pathtosvgfile = pathtosvgfile;             webbrowser.navigated += webbrowser_navigated;         }      }      private static void webbrowser_navigated(object sender, webbrowsernavigatedeventargs e)     {         var webbrowser = ((webbrowser)sender);         htmlelementcollection head = webbrowser.document.getelementsbytagname("head");          if (head != null)         {             var element = webbrowser.document.createelement("script");             element.setattribute("type", "text/javascript");             var elementdom = (mshtml.ihtmlscriptelement)element.domelement;             elementdom.src = [javascriptfile.js];             ((htmlelement)head[0]).appendchild(element);         }          webbrowser.document.body.innerhtml = string.format(webbrowser.document.body.innerhtml, pathtosvgfile);         webbrowser.navigated -= webbrowser_navigated;      } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -