मैं एक छोटा ब्राउज़र चाहता हूं जो मेरे अपने सीएसएस का उपयोग करता हो। समस्या यह है कि सीएसएस लोड नहीं होता है या, मुझे लगता है, यह लोड होता है लेकिन बिना किसी प्रभाव के।पीओओबीजेसी का उपयोग कर वेबकिट वेबव्यू में उपयोगकर्ता सीएसएस कैसे लोड करें?
import Foundation
import WebKit
import AppKit
import objc
def main():
app = AppKit.NSApplication.sharedApplication()
rect = Foundation.NSMakeRect(100,350,600,800)
win = AppKit.NSWindow.alloc()
win.initWithContentRect_styleMask_backing_defer_(rect, AppKit.NSTitledWindowMask | AppKit.NSClosableWindowMask | AppKit.NSResizableWindowMask | AppKit.NSMiniaturizableWindowMask, AppKit.NSBackingStoreBuffered, False)
win.display()
win.orderFrontRegardless()
webview = WebKit.WebView.alloc()
webview.initWithFrame_(rect)
webview.preferences().setUserStyleSheetEnabled_(objc.YES)
print webview.preferences().userStyleSheetEnabled()
cssurl = Foundation.NSURL.URLWithString_("http://dev.stanpol.ru/user.css")
webview.preferences().setUserStyleSheetLocation_(cssurl)
print webview.preferences().userStyleSheetLocation()
pageurl = Foundation.NSURL.URLWithString_("http://dev.stanpol.ru/index.html")
req = Foundation.NSURLRequest.requestWithURL_(pageurl)
webview.mainFrame().loadRequest_(req)
win.setContentView_(webview)
app.run()
if __name__ == '__main__':
main()
कोड त्रुटियों के बिना चलाता है:
यहाँ पूर्ण कोड (मैं एक अंतरफलक बिल्डर का उपयोग नहीं करते हैं) है। प्रिंट
True
http://dev.stanpol.ru/user.css
लेकिन वेबव्यू में मेरे सीएसएस का कोई प्रभाव नहीं है।
मैं डोम का लिंक जोड़ की तरह अलग अलग समाधान की कोशिश की:
pageurl = Foundation.NSURL.URLWithString_("http://dev.stanpol.ru/index.html")
req = Foundation.NSURLRequest.requestWithURL_(pageurl)
webview.mainFrame().loadRequest_(req)
dom = webview.mainFrame().DOMDocument()
link = dom.createElement_("link")
link.setAttribute_value_("rel", "StyleSheet")
link.setAttribute_value_("type", "text/css")
link.setAttribute_value_("href", "http://dev.stanpol.ru/user.css")
head = dom.getElementsByTagName_(u"head")
hf = head.item_(0)
hf.appendChild_(link)
लेकिन दोनों ही मामलों में यह काम नहीं करता।
मैं सीएसएस लोड करने के लिए जावास्क्रिप्ट का उपयोग नहीं करना चाहता।
क्या कोई मुझे बता सकता है कि मेरे कोड में उपयोगकर्ता सीएसएस सेट करने में क्या गलत है?