|
-
Mar 8th, 2007, 01:06 PM
#1
Thread Starter
Lively Member
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
-
Mar 8th, 2007, 01:18 PM
#2
Re: Disable javascript function of web page in VB6
perhaps this:
Code:
WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""
-
Mar 8th, 2007, 01:19 PM
#3
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
-
Mar 9th, 2007, 02:01 PM
#4
Thread Starter
Lively Member
Re: Disable javascript function of web page in VB6
Hi bushmobile Thanks,
Your replay
 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:
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:
Dim WithEvents objDocument As HTMLDocument
WebBrowser1 _DownloadComplete()
Set objDocument = WebBrowser1 .Document
End Sub
Private Function objDocument_onclick() As Boolean
WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""
objDocument_onclick = True
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.
-
Mar 13th, 2007, 08:55 AM
#5
Fanatic Member
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
-
Mar 13th, 2007, 02:19 PM
#6
Thread Starter
Lively Member
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
-
Mar 20th, 2007, 12:22 AM
#7
Thread Starter
Lively Member
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
-
Mar 20th, 2007, 03:41 AM
#8
Hyperactive Member
Re: Access javascript variable in VB6
 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.
-
Mar 21st, 2007, 04:57 AM
#9
Thread Starter
Lively Member
Re: Access javascript variable in VB6
Hi rnd me
 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
-
Mar 21st, 2007, 07:01 AM
#10
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)"
-
Mar 21st, 2007, 09:15 AM
#11
Thread Starter
Lively Member
Read value of JavaScript variable
Hi penagate
 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
-
Mar 21st, 2007, 09:26 AM
#12
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)
-
Mar 22nd, 2007, 09:29 AM
#13
Thread Starter
Lively Member
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:
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:
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
-
Mar 22nd, 2007, 07:55 PM
#14
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?
-
Aug 3rd, 2008, 12:07 AM
#15
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|