CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    226

    Absolute and Relative Links

    I have a drop down control and the items in it are links. The code I have to do this will work for absolute links like http://www.winzip.com:

    String url = "http://www.winzip.com";
    try { theURL = new URL(url); }
    catch ( MalformedURLException e)
    {
    System.out.println("Bad URL: " + theURL);
    }
    getAppletContext().showDocument(theURL);



    but it work work for relative links:

    String url = "index.html";
    try { theURL = new URL(url); }
    catch ( MalformedURLException e)
    {
    System.out.println("Bad URL: " + theURL);
    }
    getAppletContext().showDocument(theURL);



    Does anyone know why it won't work or how to get it to work?

    Scott
    Give a man a fish and feed him for a day,
    Teach a man to fish and feed him for life.
    _______________________________________________________
    http://welcome.to/scottweb - The Ultimate Programmers Reference



  2. #2
    Guest

    Re: Absolute and Relative Links

    I think this will work:

    try {
    URL mainURL = new URL("http://www.winzip.com");
    String rel = "index.html";
    URL theURL = new URL(mainURL, rel);
    } catch (Exception e) {
    // anything
    }




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured