使用 WebKit (Objective-C API) 的相对 CSS URL 值

发布于 2024-11-27 03:10:01 字数 777 浏览 0 评论 0 原文

我想更改 HTML 文档中背景图像属性的 URL。

DOMCSSStyleDeclaration *style = domELement.style;
NSString *imageURL = [style backgroundImage];

现在 imageURL 看起来像 url(/image.jpg)。但在 HTML 源代码中它是 url(image.jpg)。 现在我想将 image.jpg 更改为其他图像并仍然保留相对路径。我该怎么做?因为当我设置类似 url(newImage.jpg) 的内容时,渲染的输出看起来像 url(/newImage.jpg)

获取 HTML 时我可以更改一些内容吗?

DOMHTMLElement *htmlElement = (DOMHTMLElement*)[document documentElement];
NSString *html = [htmlElement outerHTML];

或者有其他方法可以在 css 属性中设置相对 URL 吗?

[style setBackgroundImage:@"url(newImage.jpg)"];

I want to change the URL's of a background-image property in a HTML document.

DOMCSSStyleDeclaration *style = domELement.style;
NSString *imageURL = [style backgroundImage];

Now the imageURL looks something like url(<base URL I've loaded the HTML with>/image.jpg). But in the HTML source it's url(image.jpg).
Now I'd like to change the image.jpg to an other image and still keep the relative path. How do I do that? Because when i set something like url(newImage.jpg) the rendered output looks like url(<base URL I've loaded the HTML with>/newImage.jpg).

May I change something when getting the HTML?

DOMHTMLElement *htmlElement = (DOMHTMLElement*)[document documentElement];
NSString *html = [htmlElement outerHTML];

Or is there an other way how I can set a relative URL in a css attribute?

[style setBackgroundImage:@"url(newImage.jpg)"];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人爱我别走 2024-12-04 03:10:01

我根本没有发现任何东西。所以我自己用 NSSCanner 解析了它

I didn't found anything at all. So I did pars it my self with an NSSCanner

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文