1
  • Hello All its simple question but am not able to answer.
  • i have written java code for html content String.
  • my goal is: when Click Here open yahoo.com & google.com pages
  • am able to open html and click on Click Here tag i am open only yahoo.com page and not able to open google.com page
  • am facing the issues with " " and ' ' symbols in right places..
  • Code is

    String content;
    content = "<html><head>....."
    +"<a href='http://yahoo.com' "
    + "onclick=\"window.open('http://google.com'); \">"
    + "Click Here</a>"
    ....
    +"</body>"
    +"</html>"
    
Kixeye User
  • 41
  • 1
  • 7
  • Is the semicolon missing in your actual code? What kind of errors are you getting? – Cartesian Theater Dec 10 '16 at 05:28
  • @CartesianTheater, thank you for replay, this String content added to `email.setHtml(content)`, in email click on ClickHere am not able open google.com, am able to open yahoo.com .. – Kixeye User Dec 10 '16 at 06:18
  • You mention this is going into an email. Email clients are a more restrictive environment for HTML content, to help protect the users from malicious code. Perhaps the email client is choosing to ignore the onclick or window.open javascript calls. – Dan Armstrong Dec 10 '16 at 07:53
  • @DanArmstrong, thank you Dan, please can you **suggest that the how to call two href for single text in email html content..** – Kixeye User Dec 10 '16 at 08:24
  • Kinda thinking outside the box a bit. But you could link to a page on a server that does the heavy lifting with a small script. The mail client opens a single URL to this script in the browser, then the browser does the "window.open" and then "window.location.href" in the script. More complicated and I left out a bunch of details, but just presenting the idea of a server component to bridge the gap. – Dan Armstrong Dec 10 '16 at 08:31

1 Answers1

0

I tried this:

public class Test{

 public static void main(String []args){
    System.out.println("Hello World");
    String content;
    content = "<html><head>"
    +"<a href='http://yahoo.com'"
    + "onclick=\"window.open('http://google.com'); \">"
    + "Click Here</a>"
    +"</body>"
    +"</html>";
    System.out.println(content);
 }

}

and pasted the resulting string into a blank html file, opened it in a browser, and saw that it worked as I expected (a link to Yahoo that opens both Yahoo and Google.).

Cartesian Theater
  • 1,920
  • 2
  • 29
  • 49
  • thank you for replay, this String content added to `email.setHtml(content)`, i got email with this html body, but in email click on ClickHere, am not able open google.com, am able to open yahoo.com .. – Kixeye User Dec 10 '16 at 06:20