【问题标题】:Removing/Stripping HTML Class from WKWebview从 WKWebview 中删除/剥离 HTML 类
【发布时间】:2017-08-03 18:01:55
【问题描述】:

我正在尝试从 WKWebview 中删除 header-padding HTML 类,这是我目前使用的方法。

func webView(webView: WKWebView,didFinishNavigation navigation: WKNavigation){


    webView.evaluateJavaScript("document.querySelector('[header-padding​]').remove();", completionHandler: { (response, error) -> Void in

    })

}

但它不起作用,这是我的 HTML。

<div class="header-padding" style="padding-bottom: 104px;">
<div class="navigation nav"><div class="nav-overlay"></div>

<header class="global-header">
<button class="search" aria-expanded="false" aria-label="show search field">
    <span class="search-icon"></span>
</button>
<button class="burger" aria-expanded="false" aria-label="show main menu">
    <span class="burger-menu"></span>
</button>
<a href="/content/insite.html" class="logo">
    <img class="logo-img" src="/etc/logo.png" alt="">
</a>

<div class="profile" aria-expanded="false">
    <div class="profileNavImg">
    <img id="header_profile_image" class="avatar profileLayoutCircle profile-show" src="/content/dam" alt="">
    </div>
</div>
</div>
</div>

任何帮助都会很棒。谢谢

【问题讨论】:

  • 我认为这个答案应该可以帮助你Call JavaScript function
  • 您的 Javascript 错误。我觉得应该是document.querySelector('.header-padding').remove()

标签: ios swift wkwebview


【解决方案1】:

您使用了不正确的查询选择器。要按类选择元素,您应该使用.

document.querySelector('.header-padding').remove();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 2014-11-15
    • 2012-09-30
    • 1970-01-01
    • 2022-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多