2012-02-24 21 views
3

在我的應用程序中,我的android設備和iPhone模擬器中工作的以下代碼。但不能在iPhone上工作javascript:href鏈接不在iPhone中工作

<a style="color:#1cffff" href="#" onclick="window.open('http://somesite.com.');"><u>mysite_name</u></a> 

我也試過這個編碼了。

<a style="color:#1cffff" href="http://somesite.com">mysite_name</a> 

以上兩種都不適用於iPhone。有沒有需要修改?快速響應幫助我lot.and thnks

+1

第二個例子究竟如何不起作用?發生什麼或沒有發生? – 2012-02-24 07:47:34

+0

它沒有工作,我可以點擊鏈接。它不會重定向到我的頁面。在Android手機和所有瀏覽器中運行良好的代碼... – Dray 2012-02-24 07:51:11

+2

發佈更多代碼。它不工作,因爲你有某種預防事件冒泡。 – andlrc 2012-02-24 09:30:10

回答

1

你的文檔中有一個HTML標籤<base>?類似這樣的:

<base href="http://somesite.com" target="_blank"> 

如果是這樣,所有的鏈接默認會在一個單獨的窗口中打開。你可能需要擺脫該元素的或明確設定了一個目標,要在同一個窗口中打開鏈接:

<a href="http://somesite.com" target="_self">Link text</a> 

這裏有some more details on the <base> element

1

試試這個,如果你使用的WebView

NSString *str [email protected]"<a style='color:#1cffff' href='http://www.somesite.com'>www.somesite.com</a>", 

[webview loadHTMLString:[NSString stringWithFormat:@"<html><body style='background-color: transparent;font-family:Helvetica;font-size:13;color: rgb(65,75,86);'>%@</body></html>",str ] baseURL:nil]; 

不能再使用

<a href="javascript:yourFunction()">Some Link</a> 
+0

它不工作..任何其他的想法? – Dray 2012-02-24 08:55:46

+0

看到我的編輯答案 – Deepesh 2012-02-24 09:28:29

+0

它沒有幫助 – Dray 2012-02-24 09:40:49

1

您可以使用這樣的事情作爲一種替代解決方案

<a href=」javascript:window.location.href=’http://google.de’」>Link</a>

這也有一個好處在全屏webapps tha你添加到主屏幕,因爲它不會將你踢出應用程序,進入Safari,但會將href加載到當前的webview中。

1

請試試這個:

<a style="color:#1cffff" href="http://somesite.com" target="_self">mysite_name</a> 
1

我不知道,因爲你告訴你已經嘗試了一切。

好的,讓我給你一些關於調試技巧的提示。

我希望它可以幫助你。只需構建適用於iPhone設備的應用程序,然後轉到該構建文件夾並打開應用程序(顯示包和內容),然後在Safari中打開您的html文件並使用safari瀏覽器的調試/開發工具,或者您可以嘗試其他brwoser調試。