• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Intercepting JavaScript calls in WebViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Intercepting JavaScript calls in WebViews


  • Subject: RE: Intercepting JavaScript calls in WebViews
  • From: "Mark" <email@hidden>
  • Date: Sun, 4 Jan 2004 18:09:05 -0700

I have the same requirement and would be interested if you discover the
right way to capture javascript calls. When working in the Windows (Internet
Explorer) world there can be a call to
windows.external.myExternalFunction(any_number_of_parameters) which I have
used successfully. I am currently searching for a similar mechanism for a
development project I have for MAC.

Any clues would be most welcome at this point.

-mark

-----Original Message-----
From: email@hidden
[mailto:email@hidden] On Behalf Of Patrick Machielse
Sent: Monday, December 15, 2003 3:28 AM
To: Jonathan Wight
Cc: Cocoa Dev List
Subject: Re: Intercepting JavaScript calls in WebViews

op 15-12-2003 00:47 schreef Jonathan Wight op email@hidden:

> On Dec 14, 2003, at 14:55, Patrick Machielse wrote:
>
>> I'm working on a project using a WebView. The html that is displayed
>> contains JavaSctipt links like:
>>
>> <a href="javascript:function(parameter);">click me</a>
>>
>> When the user clicks on a link, I must intercept the JavaScript
>> function call (which is implemented as an empty function in the html)
>> and do something intelligent with the function parameter.
>
> The easiest solution is a pure JavaScript one - but this depends on
> you controlling the content: replace 'javascript:function(parameter)'
> with something like 'javascript:'myintelligentfunction(function,
> parameter)'.

I forgot to tell: I want to do something intelligent in my main program. I
can't just do some tricks in the JavaScript sandbox (I think...)

The situation is as follows: the html displays an array of thumbnails. When
the user clicks on a thumb I must create a custom URL and download a
resource from that URL to a specific location on disc. During the download I
have to give feedback in the gui. After it finishes I have to do some setup.

> Another way (again if you control the content) then you can replace
> the 'javascript' URL scheme with something else ('x-javascript' for
> example) then register your own NSURLProtocol (and maybe an
> NSURLHandle depending on your needs) in which you do do your magic and
> pass it on to stringByEvaluatingJavaScriptFromString.

I have been thinking in the same direction. Controlling the content is easy
of course:

NSString *html = [NSString stringWithContentsOfURL:htmlURL];

// replace javascript calls...

[[webView mainFrame] loadHTMLString:html baseURL:nil];

There are some subtle problems with string encoding and the fact that
stringWithContentsOfURL: is a blocking call, but I'll ignore those for now.

WebKit seems to be pretty much a black box as far as page content is
concerned. I can't find a 'hook' into JavaScript and delving into KJS would
be overkill for this project.

Patrick
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Declarations in middle of C code?!
  • Next by Date: Re: Declarations in middle of C code?!
  • Previous by thread: Re: 'WebKit/WebKit.h' not found: now OK!
  • Next by thread: Re: Intercepting JavaScript calls in WebViews
  • Index(es):
    • Date
    • Thread