2016-12-10 169 views
1
  • 你好所有其簡單的問題,但我無法回答。
  • 我已經爲html內容字符串編寫了java代碼。
  • 我的目標是:當點擊這裏打開yahoo.com & google.com網頁
  • 我能打開HTML並點擊點擊此處標籤我打開只有yahoo.com頁無法打開google.com
  • 我所面臨的問題與「」'在正確的地方符號頁..
  • 代碼是帶有多個單引號和雙引號的java html內容

    String content; 
    content = "<html><head>....." 
    +"<a href='http://yahoo.com' " 
    + "onclick=\"window.open('http://google.com'); \">" 
    + "Click Here</a>" 
    .... 
    +"</body>" 
    +"</html>" 
    
+0

實際代碼中是否缺少分號?你得到什麼樣的錯誤? –

+0

@CartesianTheater,感謝您的重播,將此String內容添加到'email.setHtml(content)'中,在電子郵件中點擊ClickHere我無法打開google.com,能夠打開yahoo.com .. –

+0

您提到這是進入電子郵件。電子郵件客戶端是HTML內容的更嚴格的環境,以幫助保護用戶免受惡意代碼的侵害。也許電子郵件客戶端選擇忽略onclick或window.open javascript調用。 –

回答

0

我嘗試這樣做:

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); 
} 

}

並粘貼生成的字符串到一個空白的HTML文件,在瀏覽器中打開一看,只見那它按照我的預期工作(與雅虎的鏈接可以打開雅虎和Google)。

+0

感謝您的重播,將此String內容添加到'email.setHtml(content)'中,我收到了帶有這個html body的電子郵件,但是在電子郵件中單擊ClickHere,我無法打開google.com,能夠打開yahoo.com .. –