Click here to Skip to main content
16,016,168 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

how can i get the url visited from browsers (like firefox,ie,chrome etc) using java.
could you paste code.
Posted
Updated 13-Mar-16 11:35am
v2
Comments
Sandeep Mewara 18-Apr-12 10:27am    
Did you tried something? Any effort?
Nelek 18-Apr-12 17:24pm    
Of couse, he came here and wrote a post :)

Sniff browser history for improved user experience - FF & IE[^]

Access Browsing History in Google Chrome the Easy Way[^]

Have fun.

...But I should also tell you about the nowadays so important patent the Company Xerox has on 'User Profile Classification By Web Usage Analysis[^]'. And I bet there are more, so check that before starting an business.
 
Share this answer
 
public class WebBrowser {
Stack <string> backward = new Stack <string>(); // Backward pages
Stack <string> forward = new Stack <string>(); // Forward pages

public WebBrowser(Scanner sc) {
while (sc.hasNext()) {
String input = sc.nextLine();

switch(input) {
case "BACKWARD":
if (!backward.empty())
forward.push(backward.pop()); // Remove from backward, add to forward
break;

case "FORWARD":
if (!forward.empty())
backward.push(forward.pop()); // Remove from forward, add to backward
break;

default:
backward.push(input); // New page opened
while (!forward.empty()) // Clear forward stack
forward.pop();
break;
}
if (backward.empty() && !forward.empty()) // Add forward pages to history
backward.push(forward.pop());
}

if (backward.empty() && forward.empty())
System.out.println("Browsing history is empty.");

else {

// If there is only 1 page, current page in forward stack else in backward
String current = (backward.empty()) ? forward.peek() : backward.peek();

System.out.println("Browsing History:");

while (!forward.empty()) // In order to print from least to most recent
backward.push(forward.pop());

while (!backward.empty())
forward.push(backward.pop());

while (!forward.empty())
System.out.println(forward.pop());

System.out.println("Current Page:");
System.out.println(current);
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
WebBrowser bc = new WebBrowser(sc);

}

}
 
Share this answer
 
Comments
CHill60 13-Mar-16 17:41pm    
The question is nearly 4 years old!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900