To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Mar 8th, 2007, 01:06 PM   #1
nasreen
Lively Member
 
Join Date: Apr 05
Posts: 69
nasreen is an unknown quantity at this point (<10)
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
nasreen is offline   Reply With Quote
Old Mar 8th, 2007, 01:18 PM   #2
bushmobile
Oi, fat-rag!
 
bushmobile's Avatar
 
Join Date: Mar 04
Location: on the poop deck
Posts: 5,581
bushmobile is a splendid one to behold (700+)bushmobile is a splendid one to behold (700+)bushmobile is a splendid one to behold (700+)bushmobile is a splendid one to behold (700+)bushmobile is a splendid one to behold (700+)bushmobile is a splendid one to behold (700+)bushmobile is a splendid one to behold (700+)
Re: Disable javascript function of web page in VB6

perhaps this:
Code:
WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""
bushmobile is offline   Reply With Quote
Old Mar 8th, 2007, 01:19 PM   #3
Fazi
PowerPoster
 
Fazi's Avatar
 
Join Date: Aug 05
Location: Underworld
Posts: 2,525
Fazi is a jewel in the rough (300+)Fazi is a jewel in the rough (300+)Fazi is a jewel in the rough (300+)Fazi is a jewel in the rough (300+)
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
__________________
blog | Spot Your Geek
Fazi is offline   Reply With Quote
Old Mar 9th, 2007, 02:01 PM   #4
nasreen
Lively Member
 
Join Date: Apr 05
Posts: 69
nasreen is an unknown quantity at this point (<10)
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. WebBrowser1 _DownloadComplete()
  3. Set objDocument = WebBrowser1 .Document
  4. End Sub
  5. Private Function objDocument_onclick() As Boolean
  6. WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""
  7. objDocument_onclick = True
  8. 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.
nasreen is offline   Reply With Quote
Old Mar 13th, 2007, 09:55 AM   #5
TheVader
Fanatic Member
 
TheVader's Avatar
 
Join Date: Oct 02
Location: Rotterdam, the Netherlands
Posts: 871
TheVader will become famous soon enough (65+)
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:
Using the Web Browser Control & Using the DHTML Document Object Model

The examples referenced in the articles can be found here:

Last edited by TheVader; Mar 13th, 2007 at 10:00 AM.
TheVader is offline   Reply With Quote
Old Mar 13th, 2007, 03:19 PM   #6
nasreen
Lively Member
 
Join Date: Apr 05
Posts: 69
nasreen is an unknown quantity at this point (<10)
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
nasreen is offline   Reply With Quote
Old Mar 20th, 2007, 01:22 AM   #7
nasreen
Lively Member
 
Join Date: Apr 05
Posts: 69
nasreen is an unknown quantity at this point (<10)
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
nasreen is offline   Reply With Quote
Old Mar 20th, 2007, 04:41 AM   #8
rnd me
Hyperactive Member
 
Join Date: Jun 06
Posts: 372
rnd me is on a distinguished road (20+)
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.
rnd me is offline   Reply With Quote
Old Mar 21st, 2007, 05:57 AM   #9
nasreen
Lively Member
 
Join Date: Apr 05
Posts: 69
nasreen is an unknown quantity at this point (<10)
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
nasreen is offline   Reply With Quote
Old Mar 21st, 2007, 08:01 AM   #10
penagate
Super Moderator
 
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)
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)"
penagate is offline   Reply With Quote
Old Mar 21st, 2007, 10:15 AM   #11
nasreen
Lively Member
 
Join Date: Apr 05
Posts: 69
nasreen is an unknown quantity at this point (<10)
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
nasreen is offline   Reply With Quote
Old Mar 21st, 2007, 10:26 AM   #12
penagate
Super Moderator
 
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)
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)
penagate is offline   Reply With Quote
Old Mar 22nd, 2007, 10:29 AM   #13
nasreen
Lively Member
 
Join Date: Apr 05
Posts: 69
nasreen is an unknown quantity at this point (<10)
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
nasreen is offline   Reply With Quote
Old Mar 22nd, 2007, 08:55 PM   #14
penagate
Super Moderator
 
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)
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?
penagate is offline   Reply With Quote
Old Aug 3rd, 2008, 01:07 AM   #15
teguh123
Hyperactive Member
 
Join Date: Oct 07
Posts: 289
teguh123 is an unknown quantity at this point (<10)
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?
teguh123 is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:24 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.