Giter Site home page Giter Site logo

Comments (7)

HelKyle avatar HelKyle commented on September 26, 2024

看代码怎么写的了,NSPanel 创建出来就是一个弹出层

from skfe-plugin.

Nealyang avatar Nealyang commented on September 26, 2024

` var windowObject = webView.windowScriptObject();
var delegate = new MochaJSDelegate({
"webView:didChangeLocationWithinPageForFrame:": (function (webView, webFrame) {
var locationHash = windowObject.evaluateWebScript("window.location.hash");
var hash = parseHash(locationHash);
}),
"webView:didFinishLoadForFrame:": (function (webView, webFrame) {
getAllTextLayer(context);
})
});

webView.setFrameLoadDelegate_(delegate.getClassInstance());`

通过设置MochaJSDelegate可以知道webView中资源是否加载完毕,当我把弹出层的那种加载webView的方式实现后,这样是没有问题的,但是当我采用博主的方式去实现的时候,这段代码是不能加上的,会倒是闪退。

请问采用博主的这种加载webView的方式,如何知道webView中页面的js资源都加载完毕了呢

项目地址:sketch Plugin

from skfe-plugin.

Nealyang avatar Nealyang commented on September 26, 2024

因为需要在初始化的时候,就运行js中的某一个方法,也就是上面的getAllTextLayer这个方法,但是在已加载完就去执行这个方法,是没有任何效果的,估计是因为js还没有下载完成

from skfe-plugin.

HelKyle avatar HelKyle commented on September 26, 2024

@Nealyang webView 是否加载完完成是通过 delegate 去触发的,CocoaScript 执行 webview js 代码是通过 windowObject.evaluateWebScript 执行的,并不能直接调用 webview 里面的 js 代码

from skfe-plugin.

Nealyang avatar Nealyang commented on September 26, 2024

是的,但是现在的问题就是通过NSPanel,可以在"webView:didFinishLoadForFrame:"监听中去调用webView的js代码,但是通过博主的这种方式,首先webView不能够setFrameLoadDelegate_,否则直接闪退。不能够使用MochaJSDelegate,我就不知道如何判断webView中js代码是否加载完全,不然通过windowObject.evaluateWebScript执行不到js中的代码。请问博主这个有什么好的解决方法不

from skfe-plugin.

HelKyle avatar HelKyle commented on September 26, 2024

https://awkward.co/blog/how-to-create-floating-sketch-plugins-ii/ 这篇文章或许能帮到你

from skfe-plugin.

Nealyang avatar Nealyang commented on September 26, 2024

非常感谢~其实我就是参考的这篇文章写得插件

// Set the delegate on the WebView webView.setFrameLoadDelegate_(delegate.getClassInstance());

这行代码在NSPanel弹出层的那种实现方式中,这样没问题,但是如果设置成窗口的一部分,就像博主的实现方式,这句代码会引起闪退

再次感谢博主回复,我再查一查

from skfe-plugin.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.