javascript:href 链接在 iPhone 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9427165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 06:37:47  来源:igfitidea点击:

javascript: href link not working in iPhone

javascriptandroidiphoneios-simulator

提问by Dray

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

以下代码可在 Android 设备和 iPhone 模拟器上运行,但不适用于 iPhone 设备。

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

I have tried the following:

我尝试了以下方法:

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

But none of them have worked. Please advise.

但他们都没有奏效。请指教。

采纳答案by Brandan

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

<base>您的文档中有 HTML标签吗?像这样的东西:

<base href="http://somesite.com" 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.com" target="_self">Link text</a>

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

这里有一些关于<base>元素的更多细节

回答by Deepesh

try this if you use webview

如果你使用 webview 试试这个

NSString *str =@"<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];

not then use

然后不使用

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

回答by Drazen Mokic

You can use something like this as an alternative solution

你可以使用这样的东西作为替代解决方案

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

<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.

这在您添加到主屏幕的全屏 web 应用程序中也有好处,因为它不会将您踢出应用程序,进入 safari,但会将 href 加载到当前的 webview 中。

回答by Tobi

Please try this:

请试试这个:

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

回答by Praveen-K

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.

我希望它可以帮助你。只需为 iPhone 设备构建应用程序并转到该构建文件夹并打开应用程序(显示包和内容)并在 safari 中打开您的 html 文件并使用 safari 浏览器的调试/开发工具,或者您可以尝试在其他 brwoser 中调试。