473,419 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

how to follow a javascript link programaticaly?

ido

Hi all this is my first post here :)

I would like to know something about using javascript programaticaly
The thing is i have this web site on which when i press a button i
uses a function of javascript.. says exactly this in source

<a href="javascript:np('1')" ...

now when i am on that page and i type in my browsers comand line (o
address field)
javascript:np('1')
it works just as if i would have pressed the button...

now my question is how can i do the same programaticaly... i trie
using webrequest

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(textBox1.Text);
req.Method = "Post";
string strPost = "javascript:np('1')";
req.CookieContainer = new CookieContainer();
req.ContentType ="application/x-www-form-urlencoded";
Encoding utf8 = new UTF8Encoding();
byte[] content = utf8.GetBytes(strPost);
req.ContentLength = content.Length;
using (Stream requestStream = req.GetRequestStream())
{
requestStream.Write(content, 0, content.Length);
}
HttpWebResponse Response = (HttpWebResponse)req.GetResponse();
StreamReader sr = ne
StreamReader(Response.GetResponseStream(),Encoding .GetEncoding(1252));
string t = sr.ReadToEnd();
sr.Close();
Response.Close();
richTextBox1.Text=t;

like this just to dump the source of the destination page into
textwindow but when i do
req.GetResponse();
i get an exception:
The remote server returned an error: (501) Not Implemented.

is there something im doing wrong and is there a way to do this?
I mean sure there is coz the browser does this but im just weak wit
javascript and new to web
programming.. so im asking for a little help :)

Thank you for your time
Id

--
idoPosted from http://www.pcreview.co.uk/ newsgroup acces

Nov 17 '05 #1
1 6798
Hi,

The browser - surprise, surprise! - does not perform a roundtrip to the
server at all when the "javascript:" protocol is used. For example, type the
following in the browser's address line:

javascript:alert('Hello ido!'); and hit Enter.

So, to run page's JavaScript code from your C# code, you will need to do the
same thing the browser does - to parse the HTML, to extract all pieces of
JavaScript, load them all to the scripting engine (you can use the MS Script
Control OCX through COM interop as the scripting engine), expose the
document object model to the script code, to wire up events etc. ...

Sounds scary? Well, you can possibly try to have the Web Browser control to
load the page and then use the Navigate method with the "javascript:"
protocol link. This approach has its own drawbacks, but is definitely easier
than re-implementing a half of the browser. Probably there is some more
deep-level automation of the Internet Explorer - I saw people mentioning
some HTMLDocument object they tried to use. Hopefully someone who has
experience automating IE might reply here - you you should re-post your
question in an IE automation newsgroup and then return here with a follow-up
question on how the suggested thing can be done in .NET.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"ido" <ido.1qsfnm@> wrote in message
news:Iu********************@giganews.com...

Hi all this is my first post here :)

I would like to know something about using javascript programaticaly.
The thing is i have this web site on which when i press a button it
uses a function of javascript.. says exactly this in source

<a href="javascript:np('1')" ...

now when i am on that page and i type in my browsers comand line (or
address field)
javascript:np('1')
it works just as if i would have pressed the button...

now my question is how can i do the same programaticaly... i tried
using webrequest

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(textBox1.Text);
req.Method = "Post";
string strPost = "javascript:np('1')";
req.CookieContainer = new CookieContainer();
req.ContentType ="application/x-www-form-urlencoded";
Encoding utf8 = new UTF8Encoding();
byte[] content = utf8.GetBytes(strPost);
req.ContentLength = content.Length;
using (Stream requestStream = req.GetRequestStream())
{
requestStream.Write(content, 0, content.Length);
}
HttpWebResponse Response = (HttpWebResponse)req.GetResponse();
StreamReader sr = new
StreamReader(Response.GetResponseStream(),Encoding .GetEncoding(1252));
string t = sr.ReadToEnd();
sr.Close();
Response.Close();
richTextBox1.Text=t;

like this just to dump the source of the destination page into a
textwindow but when i do
req.GetResponse();
i get an exception:
The remote server returned an error: (501) Not Implemented.

is there something im doing wrong and is there a way to do this?
I mean sure there is coz the browser does this but im just weak with
javascript and new to web
programming.. so im asking for a little help :)

Thank you for your time
Ido
--
idoPosted from http://www.pcreview.co.uk/ newsgroup access


Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Rob Gordon | last post by:
Hat's off to Kaeli! I've been trying for months to get some code that would allow me to break the contents out of the main frame in my frame based navigation system- and he has almost solved...
4
by: Larry R Harrison Jr | last post by:
I have them working now, courtesy of the link given in the prior thread--the HVMenu over at Dynamic Drive myself. http://www.dynamicdrive.com I have them working as side-bar menus, not...
2
by: Joris Gillis | last post by:
Hi everyone, I have this nasty little problem to which I can't find a solution: Consider an anchor <a name="Top" id="Top">Top</a> How can I follow/execute this link from within javascript?...
5
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
1
by: Yannick Turgeon | last post by:
Hello all, I'm using A97 on W2K. I've got a form, say "frmMain" which contains a sub form, say "frmMainSub". This sub form is a "continue mode" style form (traducted from french. don't know...
1
by: noleander | last post by:
Hello. Ive got a VC++ program. Inside the program Ive got some code that has a full file path: C:\aa\bb\cc\dd\file.txt One of the folders in that path (cc) is a shortcut pointing to some...
1
by: gbraux | last post by:
Hello, I am dealing with security zones in Internet Explorer. I know how to add websites programaticaly to the intranet zone (using IInternetSecurityManager::SetZoneMapping). But do anyone...
2
by: Peter Michaux | last post by:
Hi, Below is an example of a synthetic click in Firefox. The browser does not follow the link. Is that the just the way synthetic clicks work of am I doing something wrong? I know the synthetic...
1
by: shotokan99 | last post by:
on my page, i embedded wmp this way: <object id="mplayer" codebase=http://activex.microsoft.com/activex/ con... type=application/x-oleobject align=absmiddle classid=CLSID:22d6f312-b0f6-11......
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.