Please try to understand my problem clearly.My system doesn't have internet connection but i have rendered search results using SOAP search API from other pc which is already connected to the Internet through some communication mechanism.Finally my system doesnt have internet facility.Some how i rendered search results to my system and popup search results in IE(intenet Explorer).Now user might click any one of the search results.Now my task is i need to extract the url which he clicked just now.Is there any another viewer which could display the HTML contents?Hw could i do that please suggest me?
Actaully i would like to know browser Event Handling.E.g I have .html file which is displayed on the IE.Now user may select one url from set of urls present in the HTML page.Hw could i know which url user has selected just now.Is this possible with java script?Please suggest me?
When you said "...which url user has selected...", are you talking about selecting urls from a list (html "select" element with "options" filled with urls), or clicking on a "href" element ? --> For the first option, you can add onchange, onFocus, ... events on your select. Example: HTML CODE: <select id="urllist" onchange="f_selected(this.selectedIndex)" onfocus="f_selected(this.selectedIndex)" > <option value="url1">http://www.site1.com</option> <option value="url2">http://www.site1.com</option> <option value="url3">http://www.site1.com</option> </select> JAVASCRIPT CODE: function f_selected(p_index) { var v = document.getElementsByTagName( "option" )[p_index]; ... } Code (markup): --> For the second option, you can view an example on this other thread: http://forums.digitalpoint.com/showthread.php?t=187903
Thankx for ur reply.I have still one more doubt.I will discuss my problem with an example. <html> <body> <a href="http://www.yahoo.com">Yahooo</a> <a href="http://www.google.com">Google</a> <a href="http://www.nvdia.com">NVDIA</a> </body> </html> this is my html page with set of Hrefs.Now my task is how to retrieve the Href part like http://www.yahoo.com whenever user clicks yahoo.And same for remaing hrefs.Is there any java script to achieve this?Please give me reply. thanking you inadvance.
Try this. It will alert the href. function chgLinks() { for(lnk in document.links){ lnk = document.links[lnk]; lnk.onclick = function(){ alert(lnk.href) }; } } document.onload = chgLinks; Code (markup):
thankx for ur reply.Following is my code.Is there any changes that i have to do inorder to fulfill my task.Please note i am new to java script. <html> <head> <script LANGUAGE="JavaScript"> function chgLinks() { for(lnk in document.links){ lnk = document.links[lnk]; lnk.onclick = function(){ alert(lnk.href) }; } } document.onload = chgLinks; </script> </head> <body> <a href="http://www.google.com" >Google</a> <a href="http://www.yahoo.com" >Yahoo</a> <a href="http://www.nvdia.com" >NVDIA</a> </body> </html> thanking you inadvance.
The code above does not work. Try this: <html> <head /> <body onload="chgLinks()"> <script type="text/javascript"> function myalert() { alert( this.href ); } function chgLinks() { var a = document.getElementsByTagName("a"); for(i=0; i<a.length; i++) { a[i].onclick = myalert; } } </script> <a href="http://www.google.com" >Google</a> <a href="http://www.yahoo.com" >Yahoo</a> <a href="http://www.nvdia.com" >NVDIA</a> </body> </html> Code (markup): This code is a simplified version taken from the code on this thread: "counting clicks with static links".
I am sorry. I took it from a web directory I created long back. Made some modification to it quickly and didn't test it. Here is the modified code. function chgLinks() { for(lnk in document.links){ lnk = document.links[lnk]; lnk.onclick = function(){ [COLOR="Red"]alert(this.href); return false;[/COLOR] }; } } window.onload = chgLinks; Code (markup): Ofcourse, see the part I have marked in red. Presently what it does is show a msg box with the link url. Change it with what you want to do. The url is available in this.href. If you use the return false statement, then the page will not redirect to the link url. See the difference by clicking on the link with and without the return false statement.
thanking you very much for ur reply.It's working.Now i have one more doubt.Is there any way inorder to communicate from java script to java application. <html> <head /> <body onload="chgLinks()"> <script type="text/javascript"> function chgLinks() { for(lnk in document.links){ lnk = document.links[lnk]; lnk.onclick = function(){ alert(this.href); return false; }; } } </script> <a href="http://www.google.com" >Google</a> <a href="http://www.yahoo.com" >Yahoo</a> <a href="http://www.nvdia.com" >NVDIA</a> </body> </html> in this code how could i pass "this.href" java script var to java variable. thanking you inadvance.
Suppose the name of the java applet is 'myapplet'. Then you can access the methods and variables in the applet as given below document.[B]myapplet[/B].[I]methodname[/I](args_here); document.[B]myapplet[/B].[I]varname[/I] = this.href; Code (markup): More information on accessing Java from Javascript More information on accessing Javascript from Java