473,406 Members | 2,705 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,406 software developers and data experts.

add js client side

Is it possible to add a js function to a loaded web page on the client side?
E.g. IE is viewing google, can I add a javascript function to that instance
of IE viewing google? I am trying to hook browser events such as button
clicks and get information such as edit field text.

Thanks IA, Simon
Jul 20 '05 #1
4 1543
Ivo
"Simon" <si****************@btinternet.please.com> wrote in message
news:c1**********@sparta.btinternet.com...
Is it possible to add a js function to a loaded web page on the client side? E.g. IE is viewing google, can I add a javascript function to that instance of IE viewing google? I am trying to hook browser events such as button
clicks and get information such as edit field text.


With your webbrowser parked at your preferred google page, type this in the
addressbar:

javascript:function x(){p=prompt('Your name...');alert('Welcome to Google,
'+p) }; void(x());

and hit return. You won't leave the page (if you didn't make a typing
mistake).
As you can see, you have just added a function called x to the current page.
It 's the type of scripting upon which bookmarklets are based. It will work
with any site. But it will only work for that specific copy of the page in
your browser and only until you leave the page. SO it will only be your own
clicks that you will be able to monitor.
And Internet Explorer 6 has reduced support for it: your code should not be
longer than 208 (or was it 255?) characters or it will be ignored. A
workaround in modern bookmarklets is to dedicate those 208 characters to
inserting a .js file on the fly, with something like
z=document.createElement('script');
z.src="http://mysite.com/myscriptonyoursite.js"
HTH
Ivo


Jul 20 '05 #2
> With your webbrowser parked at your preferred google page, type this in
the
addressbar:

javascript:function x(){p=prompt('Your name...');alert('Welcome to Google, '+p) }; void(x());

and hit return. You won't leave the page (if you didn't make a typing
mistake).
As you can see, you have just added a function called x to the current page. It 's the type of scripting upon which bookmarklets are based.


Thanks for that - looks useful. I want to make the process automatic (i.e.
without typing in the address bar) - any ideas? I guess I can probably hook
the address bar and update it but I'd rather use a neater method if you know
of one?

Simon
Jul 20 '05 #3
Ivo
"Simon" <si****************@btinternet.please.com> wrote in message
news:c1**********@titan.btinternet.com...
With your webbrowser parked at your preferred google page, type this in the
addressbar:

javascript:function x(){p=prompt('Your name...');alert('Welcome to

Google,
'+p) }; void(x());

and hit return. You won't leave the page (if you didn't make a typing
mistake).
As you can see, you have just added a function called x to the current

page.
It 's the type of scripting upon which bookmarklets are based.


Thanks for that - looks useful. I want to make the process automatic (i.e.
without typing in the address bar) - any ideas? I guess I can probably

hook the address bar and update it but I'd rather use a neater method if you know of one?

Simon


I got a present for you, Simon. Like a proper present, you need to carefully
unwrap it, that is copy and paste each of the following lines in your
address bar, one after another, without spaces or other noise in between
(meanwhile, look at the code and guess what is going to happen), so that it
becomes one line again:

javascript:void((function(){var s='';(function(w){for(var
i=0;i<w.length;i++){arguments.callee(w.frames[i]);}try{s+=w.document.selecti
on.createRange().text;}catch(e){try{s+=w.document. getSelection();}catch(e){a
lert('Bookmarklet failed:\n\n'+e.message);}}})(top);if(!s)s=prompt(' Enter
keywords:','');if(s)location='http://www.google.com/search?q='+escape(s);})(
))

If you 're confident all is well, hit return and if you haven't selected any
text on the current page, you will be prompted for a search query. You can
save this javascript code in your Favorites, on your Personal Toolbar even,
if you write it in an <a href="javascript:..." tag and bookmark that link.
There are other, more convenient ways but there re not all easy to explain
unless bookmarklets tickle your imagination.

Also see:
http://www.bookmarklets.com/tools/search/ introduces you to dozens of
bookmarklets, specifically engineered for faster searching.
http://www.bookmarklets.com/mk.phtml even has a bookmarklet to helps you in
creating bookmarklets for any search engines not yet listed.

HTH
Ivo
Jul 20 '05 #4
> I got a present for you, Simon. Like a proper present, you need to
carefully
unwrap it, that is copy and paste each of the following lines in your
address bar, one after another, without spaces or other noise in between
(meanwhile, look at the code and guess what is going to happen), so that it becomes one line again:

javascript:void((function(){var s='';(function(w){for(var
i=0;i<w.length;i++){arguments.callee(w.frames[i]);}try{s+=w.document.selecti on.createRange().text;}catch(e){try{s+=w.document. getSelection();}catch(e){a lert('Bookmarklet failed:\n\n'+e.message);}}})(top);if(!s)s=prompt(' Enter
keywords:','');if(s)location='http://www.google.com/search?q='+escape(s);})( ))

Thanks - that's cool :)
Is there a way that a bookmarklet can be run with a link. For example, some
PC has a link that points to a web app - something like http://192.168.1.22.
Can the bookmarklet be appended to the link somehow so that the web site
opens and the bookmarklet runs?
Also see:
http://www.bookmarklets.com/tools/search/ introduces you to dozens of
bookmarklets, specifically engineered for faster searching.
http://www.bookmarklets.com/mk.phtml even has a bookmarklet to helps you in creating bookmarklets for any search engines not yet listed.


I had a look at those and also http://tantek.com favelet - I'll need to
study them for a while.

Simon
Jul 20 '05 #5

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

Similar topics

9
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side...
11
by: Tom Leylan | last post by:
(I posted this in languages.vb also... I can't figure out where things go if you use a little of a lot of things) Hi all... I'm looking for an example (or a pointer to one) related to the...
2
by: Dicky Cheng | last post by:
Hi, I am using .net remoting technology. I set up a .net remoting client and server in IIS. When the client calls the server, the server will run a long duration method (30-60seconds). I have a...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
6
by: Ken Allen | last post by:
I am relatively new to .Net and C#, but I hav ebeen programing in other languages and done some COM work for a number of years. I am attempting to understand how to map an older program...
4
by: | last post by:
Hello Guys, I am using the validation controls to validate my data. But the problem is "The page is still being posted to server". I want to get rid of the round trips to server. Are there...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
10
by: Ben | last post by:
Hi, I made an application in classic asp (reservation of books and video stuffs for students) and want to migrate to asp.net. The user has to chose a date, then pushung on a submit button. The...
3
by: Simon Brooke | last post by:
I've been doing XSL transforms, converting XML to HTML, server side since 2000. In those days, clients which could do the transformation client side didn't exist, so whether to transform...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...

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.