Results 1 to 6 of 6

Thread: How to Call function in .JS file | Pass 2 parameters | Get Result as String

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    100

    How to Call function in .JS file | Pass 2 parameters | Get Result as String

    I'm trying to call a javascript function from within VB6.


    Details:


    * The javascript function is contained in a file named "htmlparser.js" and this file is installed along side the .EXE file when the application is installed.


    * The function is called "parse" and it takes 2 parameters: URL and HTML


    The function call looks like this:


    Code:
    htmlparser.parse(url, {html: '<html><body><p>Some HTML to be Parsed</p></body></html>',}).then(result => console.log(result));
    How can I call this function from VB6 and retrieve the result into a string variable? Do I use .execscript or wscript or what?


    TIA

  2. #2
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How to Call function in .JS file | Pass 2 parameters | Get Result as String

    google v8.dll

  3. #3
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: How to Call function in .JS file | Pass 2 parameters | Get Result as String

    You don't need any javascript-support, to read-out the plain-text from some HTML-Document-input
    (if that's what you are after, which isn't entirely clear)...

    FWIW, here's a simple function, which does just that:
    Code:
    Private Sub Form_Load()
      Debug.Print HtmlToText("<html><body><p>Some HTML to be Parsed</p></body></html>")
    End Sub
    
    Function HtmlToText(sHTML As String) As String
      With CreateObject("htmlfile")
        .write sHTML: HtmlToText = .body.innerText
      End With
    End Function
    Olaf

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    100

    Re: How to Call function in .JS file | Pass 2 parameters | Get Result as String

    Can I access the the functions in v8.dll from VB6? Can I just add v8.dll via the References menu and call its functions?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    100

    Re: How to Call function in .JS file | Pass 2 parameters | Get Result as String

    This JS parse function produces clean HTML so you get the text portion without losing the links and images.

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: How to Call function in .JS file | Pass 2 parameters | Get Result as String

    Quote Originally Posted by zlander View Post
    This JS parse function produces clean HTML so you get the text portion without losing the links and images.
    Without any example-outputs (and the source of htmlparser.js), this will remain a "guessing-game".

    Olaf

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width