|
|
#1 |
|
Lively Member
Join Date: Apr 05
Posts: 69
![]() |
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> With regards, Nasreen |
|
|
|
|
|
#2 |
|
Oi, fat-rag!
Join Date: Mar 04
Location: on the poop deck
Posts: 5,581
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Disable javascript function of web page in VB6
perhaps this:
Code:
WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""
__________________
Take a moment to rate useful posts VB6 CodeBank: Glass Form & Tracing App , MouseWheel with Any Control , Form Previewer Utility VB6 Snippets: RTB: Disable Smooth Scrolling , Form: Left & Right Justified Text in TitleBar , ListBox: As-You-Type Filtering (fast) , MSFlexGrid: Non-Adjacent Col/Row Selection , IsProcessRunning: PSAPI / WMI , PictureBox: Frame Look-A-Like , Open Folder in a Particular View , Form: Always on Bottom VBA Snippet: Generic Mouseover Workaround |
|
|
|
|
|
#3 |
|
PowerPoster
Join Date: Aug 05
Location: Underworld
Posts: 2,525
![]() ![]() ![]() ![]() |
You can disable total script access through registry for IE . But for a specific js function with in an specific html page
|
|
|
|
|
|
#4 | |
|
Lively Member
Join Date: Apr 05
Posts: 69
![]() |
Re: Disable javascript function of web page in VB6
Hi bushmobile Thanks,
Your replay Quote:
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:
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:
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 |
|
Fanatic Member
Join Date: Oct 02
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()
__________________
Author for Visual Basic Web Magazine My articles on the Web Browser Control: Last edited by TheVader; Mar 13th, 2007 at 10:00 AM. |
|
|
|
|
|
#6 |
|
Lively Member
Join Date: Apr 05
Posts: 69
![]() |
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 |
|
Lively Member
Join Date: Apr 05
Posts: 69
![]() |
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 | |
|
Hyperactive Member
Join Date: Jun 06
Posts: 372
![]() |
Re: Access javascript variable in VB6
Quote:
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 | |
|
Lively Member
Join Date: Apr 05
Posts: 69
![]() |
Re: Access javascript variable in VB6
Hi rnd me
Quote:
With regards, Nasreen |
|
|
|
|
|
|
#10 |
|
Super Moderator
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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 | |
|
Lively Member
Join Date: Apr 05
Posts: 69
![]() |
Read value of JavaScript variable
Hi penagate
Quote:
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 |
|
Super Moderator
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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 |
|
Lively Member
Join Date: Apr 05
Posts: 69
![]() |
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:
vb Code:
Can u forward me a solution. With regards, Nasreen |
|
|
|
|
|
#14 |
|
Super Moderator
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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 |
|
Hyperactive Member
Join Date: Oct 07
Posts: 289
![]() |
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? |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|