zhangqd / chromiumembedded

Automatically exported from code.google.com/p/chromiumembedded
0 stars 1 forks source link

Loading .js file is not working #1251

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm in the process of integrating CEF3 into my current project as there are 
increasingly javascript functions I am adding, it makes sense to put all 
javascript functions into a separate .js file, and load it into html as

<script type="text/javascript" src="http://internal/helper.js"></script>

However, it doesn't work for some reason and I have tried without the custom 
link like

<script type="text/javascript" src="helper.js"></script>

and still received the same error - ["Uncaught ReferenceError: showAlert is not 
defined", source: http://internal/tests.html]

My code is built on top of cefsimple example, and there is no custom scheme has 
been defined, I have a method to load resource based on mine type (ParseTestUrl 
method), that's why loading http://internal/index.html works fine

CefRefPtr<CefResourceHandler> SimpleHandler::GetResourceHandler(
                                                                CefRefPtr<CefBrowser> browser,
                                                                CefRefPtr<CefFrame> frame,
                                                                CefRefPtr<CefRequest> request) {
    std::string url = request->GetURL();
    if (url.find(kInternalOrigin) == 0) {
        // Handle URLs in the test origin.
        std::string file_name, mime_type;
        if (ParseTestUrl(url, &file_name, &mime_type)) {
            // Load the resource from file.
            CefRefPtr<CefStreamReader> stream =
            GetBinaryResourceReader(file_name.c_str());
            if (stream.get())
                return new CefStreamResourceHandler(mime_type, stream);
        }
    }

    return NULL;
}

Could anyone shed some light on what I did wrong? What would be the best way to 
achieve my goal without having to define custom scheme?

Thanks in advance.

Original issue reported on code.google.com by mutulong on 14 Apr 2014 at 10:42

GoogleCodeExporter commented 9 years ago
Please ask questions on the CEF Forum instead of the issue tracker: 
http://magpcss.org/ceforum/

Based on the error that you're receiving it seems that the js file is loading 
fine, but that there's an error in your JavaScript code. You can use DevTools 
to debug further.

Original comment by magreenb...@gmail.com on 15 Apr 2014 at 7:10