我构建了一个小型应用程序,它通过 ajax 将博客信息提取到应用程序中,允许用户查看标题列表,然后单击动态创建的页面上的主要详细信息。
一切都运行良好,但在一个页面上,提要包含一个带有 target="_blank" 的链接。当在 iPhone 或模拟器上动态创建页面时,它会在 safari 中打开链接,无需单击任何内容。
我猜我需要更改链接,删除 'target=_blank"' 并替换为 'rel="external"' 但事实证明如何做到这一点有点困难。
我已经尝试过了:
var text = $(this).find('description').text().replace(/(http[s]?:\/\/[a-zA-Z0-9\.\-\_\/\?\%\#\&\=]+)/g, "<a class='atag' href='$&'>$&</a>");
这确实找到了链接,但替换所有内容,不仅仅是删除目标,这不会那么糟糕,但 a href 包装图像,而不是文本,因此以这种方式重新格式化将不起作用
。
更新*
经过一番挖掘,它实际上是在新窗口中打开的博客内容中的一个 iframe。所以看起来我需要删除
I have built a small app that pulls blog information via ajax into the app allowing the user to view a list of titles then click through to the main detail on a dynamically created page.
Everything is working great, but on one page the feed hold a link with target="_blank" on it. When the page is dynamically created on the iPhone or simulator, it opens the link with-in safari, without anything being clicked.
I'm guessing I need to change the link removing the 'target=_blank"' and replacing with 'rel="external"' but how to do this is proving a little difficult.
I have had a go with:
var text = $(this).find('description').text().replace(/(http[s]?:\/\/[a-zA-Z0-9\.\-\_\/\?\%\#\&\=]+)/g, "<a class='atag' href='amp;'>amp;</a>");
This does find the link, but replaces everything not just removing the target, which wouldn't be so bad, but the a href wraps a image, not text so reformatting this way won't work.
Any help more than welcome.
UPDATE*
After a bit of digging, it is actually an iframe that is within the blog content that is opening in a new window. So looks like I need to remove a <iframe
... not a target attribute.
发布评论
评论(1)
我认为这应该可以解决删除目标并将其替换为 rel="external" 的问题:
I think this should do the trick of removing the target and replacing it with rel="external":