Coder Social home page Coder Social logo

Comments (8)

alinz avatar alinz commented on September 6, 2024

Hello @KevinGrandon,
Thanks for kind words. I have implemented the eval for the project but I have not be able to find a time to document it properly. Here the code that does the execution. At the moment you can't load the file and execute it. What you have to do is pass the a valid javascript string into webviewRef.eval() method.

 componentDidMount() {
    var webviewRef = this.refs[WEBVIEW_REF];
    webviewRef.eval('window.MyInternalVariable=100');
  }

let me know if you need more help.

from react-native-webview-bridge.

KevinGrandon avatar KevinGrandon commented on September 6, 2024

Hi, thanks for the quick response! I agree that the eval method is useful, but I do think it would be nice to be able to wrap it in a way which could load content from a file on disk (as you might need to execute a large amount of script).

I'm going to play with this to see if I can implement what I am thinking of, and might be able to send you a pull request.

from react-native-webview-bridge.

alinz avatar alinz commented on September 6, 2024

Agreed, you might want to look into this since WebViewJavascriptBridge loads WebViewJavascriptBridge.js.txt as a file and injects it into webview. You might simply add a new method and duplicate the code there and replace it with some file content loader.

from react-native-webview-bridge.

KevinGrandon avatar KevinGrandon commented on September 6, 2024

Well, maybe this is not needed. I've found a workaround, and here it is if anyone finds this in the future:

var script = '(' + require('my-script.js').toString() + '());';
webviewRef.eval(script);

from react-native-webview-bridge.

MossP avatar MossP commented on September 6, 2024

@KevinGrandon - Do you have an example of some script that you were able to execute inside the webview? I'm struggling just get an alert box to show.. I'm using your load & inject script and pointing to a basic test script

<script>
document.addEventListener("DOMContentLoaded", function(event) {
  window.alert('injected into site!');
});
</script>

from react-native-webview-bridge.

MossP avatar MossP commented on September 6, 2024

OK. I worked it out. I didn't need any of the preface, just simply the call to window.alert(). That should enable me to continue. Thanks for this plugin @alinz . Great work :)

from react-native-webview-bridge.

alinz avatar alinz commented on September 6, 2024

@MossP I have upgraded to 0.3.0. You might want to use this version instead.

from react-native-webview-bridge.

MossP avatar MossP commented on September 6, 2024

Thanks @alinz, I'll take a look.

from react-native-webview-bridge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.