Results 1 to 15 of 15

Thread: Disable javascript function of web page in VB6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Disable javascript function of web page in VB6

    Hi All,

    Is there any idea to disable the run of a javascript function of an HTML page in VB6.

    Here is the HTML tags
    HTML Code:
    <input type="button" name="Submit" value="NEXT" onClick=next_clicked() >
    
    <Script>
    function next_clicked()
    {
    .......
    .......
    .......
    }
    </Script>
    Is there any idea using DOM to disable the run of function next_clicked() in VB6 when the button NEXT is clicked


    With regards,
    Nasreen

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Disable javascript function of web page in VB6

    perhaps this:
    Code:
    WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""

  3. #3
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Talking Re: Disable javascript function of web page in VB6

    You can disable total script access through registry for IE . But for a specific js function with in an specific html page

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Disable javascript function of web page in VB6

    Hi bushmobile Thanks,

    Your replay
    Quote Originally Posted by bushmobile
    perhaps this:
    Code:
    WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""
    Your code is working fine.
    But if I want again to allow the run of the same javascript function what can I do ?
    Because my VB code check some conditions, If conditions are true, I want allow to run the javascript funtion, if conditions are false, I want to stop the run of that function.
    Your code stop the run of the function, but now I want to allow the run of the function if all conditions are true.

    I wrote the below code to run the funtion:
    VB Code:
    1. WebBrowser1.document.getElementsByName("Submit")(0).onclick  = "next_clicked()"
    But it doesn't work. I hope you may have an idea to solve this.

    And can u explain me what is the use of (0) in the code you suggested [....("Submit")(0).onclick]

    And secondly, I run this code under the event of DownloadComplete () of WebBrowser1
    I tried to run this code under onclick() event of an object I declared WithEvents and set WebBrowser1 to it.

    Here is the code sample

    VB Code:
    1. Dim WithEvents objDocument As HTMLDocument
    2.  
    3. WebBrowser1 _DownloadComplete()
    4. Set objDocument = WebBrowser1 .Document
    5. End Sub
    6.  
    7. Private Function objDocument_onclick() As Boolean
    8. WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""
    9. objDocument_onclick = True
    10. End Function

    But the javascript function run before the onclick() is triggered.

    So is there any idea to control the run of javascript funtion under onclick() event or any similary events.

    With regards,
    Nasreen
    Last edited by nasreen; Mar 9th, 2007 at 02:06 PM.

  5. #5
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: Disable javascript function of web page in VB6

    Hi nasreen,

    I think the best way to reenable a JavaScript function is using the attachEvent method (MSDN). In your case, that would be something like this:
    Code:
    WebBrowser1.document.getElementsByName("Submit")(0).attachEvent "onclick", WebBrowser1.document.parentWindow.next_clicked()
    Last edited by TheVader; Mar 13th, 2007 at 09:00 AM.
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Disable javascript function of web page in VB6

    Hi TheVader

    Thanks for your best advice.
    The code is working fine.
    Thanks once again

    With regards,
    Nasreen

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Access javascript variable in VB6

    Hi Mr. TheVader

    Can we access (read/write) the javascript variables, in functions or out of functions, in VB6 using DOM ?

    Any idea ?

    With regards,
    Nasreen

  8. #8
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    Re: Access javascript variable in VB6

    Quote Originally Posted by nasreen
    Hi Mr. TheVader

    Can we access (read/write) the javascript variables, in functions or out of functions, in VB6 using DOM ?

    Any idea ?

    With regards,
    Nasreen
    YES! code injection is quite possible.
    if you need to change a lot on the web page, the easiest was (umm granted you're familier with scripting) is to put your code into a file and add a new scipt tag pointing to the file. i use the free ramdisk that came with xp for that very purpose.

    the simplest way to add a script would be to modify something's innerHTML and put the tag inside.

    think of it as greasemonkey for IE.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Access javascript variable in VB6

    Hi rnd me
    Quote Originally Posted by rnd me
    YES! code injection is quite possible.
    if you need to change a lot on the web page, the easiest was (umm granted you're familier with scripting) is to put your code into a file and add a new scipt tag pointing to the file. i use the free ramdisk that came with xp for that very purpose.

    the simplest way to add a script would be to modify something's innerHTML and put the tag inside.

    think of it as greasemonkey for IE.
    Thanks, but I have no much idea about code injection. Can u pls give me a clear picture on this method. If you describe with an example it may be a greatful help.

    With regards,
    Nasreen

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Disable javascript function of web page in VB6

    As far as I know, the WebBrowser exposes no programmatic method of altering Javascript variables at run-time, but you can execute a Javascript statement like this:

    Code:
    WebBrowser1.Navigate2 "javascript:my_variable = value;void(0)"

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Read value of JavaScript variable

    Hi penagate
    Quote Originally Posted by penagate
    As far as I know, the WebBrowser exposes no programmatic method of altering Javascript variables at run-time, but you can execute a Javascript statement like this:

    Code:
    WebBrowser1.Navigate2 "javascript:my_variable = value;void(0)"
    Thanks for replay,
    What I want really in my project is to read value of some variables. I don't want to change the value, but I want to read.

    Is it possible to read the value of a vairable in JavaScript ?

    Wiht regards,
    Nasreen

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Disable javascript function of web page in VB6

    I really don't know of an elegant way, but you could create a temporary element in the page, give it an ID, execute a JS statement to write the variable value into that element, and then read it out using the DOM.

    Code:
    Dim tempElement As IHTMLElement
    Dim variableContents As String
    
    ' Create a temporary span element:
    Set tempElement = WebBrowser1.document.body.CreateElement("span")
    tempElement.id = "temp_var"
    
    ' Dump the variable contents into the span:
    WebBrowser1.Navigate2 _
      "javascript:document.getElementById('temp_var').innerHTML = variable_name;void(0)"
    
    ' Grab it into our app:
    variableContents = tempElement.innerHTML
    
    ' Delete the temporary element:
    tempElement.parentNode.RemoveChild(tempElement)

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Disable javascript function of web page in VB6

    Hi Mr. penagate

    Thanks for your help with code,
    I have hope this code can perform the task that I want really.
    But I have some problems using this code.


    VB Code:
    1. WebBrowser1.Navigate2 "javascript:document.getElementById('temp_var').innerHTML = variable_name;void(0)"
    The above line always shows an Internet Explorer Script Error , saying Error : 'Document' is undefined

    vb Code:
    1. tempElement.parentNode.removeChild (tempElement)
    This line shows run time error saying Object variable or With variable not set

    Can u forward me a solution.

    With regards,
    Nasreen

  14. #14
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Disable javascript function of web page in VB6

    document is undefined? Well that's impossible, unless you haven't loaded a web page yet. Have you?

  15. #15
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Disable javascript function of web page in VB6

    I am automating a website.

    There is this one part where once in a while a page is not published. If I want to move on and navigate away, a javascript pops out show up asking whether I am sure that I want to navigate away because the there is some unsaved change.

    Well, I did (dw1 is htmldocument of the object)

    dw1.body.innerhtml=""
    dw1.scripts(0).outerrhtml=""
    dw1.scripts(0).outerrhtml=""

    Now, if I view the source, the source is still exactly the same.

    however, if I do ?dw1.all(0).outerhtml, I see that all the scripts have been removed.

    However, if I close the internet explorer the same annoying pop up message still show up.

    How do I get rid javascript in that page?

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