views:

325

answers:

2

Objective-c, Webview

Hello, I'm trying to change the innerHTML of an DOM elemnent in a DOMDocument:

DOMDocument *myDOM = [[storyDisplay mainFrame] DOMDocument]; DOMElement *heading = [myDOM getElementById:@"heading"]; [heading setNodeValue:@"hejsa"];

Nothing seems to change when the above lines are executed, is this the right way to edit the innerHTML attribute?

Thanks, Mads Hartmann Jensen

A: 

I found out that one way to achieve this was to use Javascript to play around with the DOM:

id *scriptObject= [storyDisplay windowScriptObject]; 
[scriptObject callWebScriptMethod:@"repleaceHeader" withArguments:[[NSArray alloc] initWithObjects:@"Whatever you want the header to be"]];

This bit of code gets the scripting environment from the webview and executes a javascript function by the name 'replaceHeader' with and array of argument (in my case only a string).

This require that you have a javascript function with that name, part of my html document looks like this:

<h1 id="heading">Welcome to Cookie</h1>
<script type="text/javascript">
function repleaceHeader(header) { 
    var heading = document.getElementById("heading"); 
    heading.innerHTML = header; 
}    
</script>
Mads H
A: 

Why not just use the -setInnerHTML: method?

Mike Abdullah
wow, no idea how i missed that method, thanks a lot
Mads H