admin管理员组

文章数量:1290338

The following piece of code is working on Android devices and iPhone simulator but not working on the iPhone device.

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

I have tried the following:

<a style="color:#1cffff" href="">mysite_name</a>

But none of them have worked. Please advise.

The following piece of code is working on Android devices and iPhone simulator but not working on the iPhone device.

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

I have tried the following:

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

But none of them have worked. Please advise.

Share Improve this question edited Oct 7, 2019 at 6:48 Rohit416 3,4963 gold badges26 silver badges42 bronze badges asked Feb 24, 2012 at 7:46 DrayDray 1,9545 gold badges27 silver badges42 bronze badges 11
  • 2 How exactly is the second example not working? What happens or doesn't happen? – Pekka Commented Feb 24, 2012 at 7:47
  • its not working.i am able to click the link. its not redirecting to my page.the same code working good in android phones, and all browsers... – Dray Commented Feb 24, 2012 at 7:51
  • 2 Post some more code. It's not working because you have some kind of prevented event bubbling. – Andreas Louv Commented Feb 24, 2012 at 9:30
  • just I am displaying the link inside a div. its very simple. not much code involved. Code is working fine fo all browsers and phones except iPhone. is there any other way for redirecting the user to mywebsite when they click on the link?? – Dray Commented Feb 24, 2012 at 9:47
  • 1 What you posted is perfectly valid HTML (even though a bad practice). You really should let us see your Javascript code. If the code is working fine everywhere except iPhone, then obviously iPhone's problem must be the Javascript code of yours. – Petr Vostrel Commented Mar 22, 2012 at 12:43
 |  Show 6 more ments

5 Answers 5

Reset to default 1 +50

Do you have an HTML <base> tag in your document? Something like this:

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

If so, all of your links will open in a separate window by default. You'll probably need to get rid of that element or explicitly set a target on links that you want to open in the same window:

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

Here are some more details on the <base> element.

try this if you use webview

NSString *str =@"<a style='color:#1cffff' href='http://www.somesite.'>www.somesite.</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];

not then use

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

You can use something like this as an alternative solution

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

This has also a benefit in fullscreen webapps that you added to homescreen since it won't kick you out of the app, into safari but will load the href into the current webview.

Please try this:

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

I do not know as you told you have tried everything there.

Okay so let me give you some hint regarding debugging tips.

I hope it may help you out. Just build the app for iPhone device and go to that build folder and open the app (show package and contents) and open your html file in safari and use the debug/development tool of safari browser or you may try in other brwoser for to just debug.

本文标签: androidjavascript href link not working in iPhoneStack Overflow