I want to load custom html in a webview using react native, it's working for simple html but I can't figure out how to load javascript from a js file to the webview, it looks like nothing happen.
Here is my webview :
var html = '<!DOCTYPE html><html><head><script src="myfile.js" type="text/javascript"></script></head><body><h1>This is a heading!</h1><div id="here"></div></body></html>';
return (
<WebView html={html}
javaScriptEnabled={true} />
);
And here I have my simple js file (myfile.js):
document.addEventListener("DOMContentLoaded", function(event) {
alert("HERE");
var generateHere = document.getElementById("here");
generateHere.innerHTML = '<div class="someclass"><a href="www.example.com"><p>some text</p></a></div>';
});
I tried it in my web browsers it works.
myfile.js?