alinz / react-native-webview-bridge

React Native Webview with Javascript Bridge
MIT License
1.37k stars 491 forks source link

[Android] injectScript not work #200

Closed qq326646683 closed 7 years ago

qq326646683 commented 7 years ago

https://github.com/alinz/react-native-webview-bridge/issues/69

hi,Alinz,I also can't deal with it,need your help ,thanks

qq326646683 commented 7 years ago

@alinz

avishayil commented 7 years ago

same here, using version 2.

qq326646683 commented 7 years ago

@avishayil are you successful ?can you tell me how to use v2 detailly?

avishayil commented 7 years ago

Couldn't make it work for now.

thedjinn commented 7 years ago

I have also encountered this, only on Android. As I was using jQuery inside my page I decided to move the injected code to the jQuery ready function inside the HTML file. This works fine.

qq326646683 commented 7 years ago

Can you send your code about this to me,thank you evry much . my email is 326646683@qq.com @thedjinn

thedjinn commented 7 years ago

I would say this is a rather trivial thing to find out yourself.

qq326646683 commented 7 years ago

@thedjinn I agree with you ,I will deal with it quikly with your help if you have time.I spend a lot of time at here

qq326646683 commented 7 years ago

no one can't deal with it,I can't believe it,We need your help,thank you so much @alinz

avishayil commented 7 years ago

I solved it in an ugly way. Check my fork.

On Mon, Jan 16, 2017, 11:08 qq326646683 notifications@github.com wrote:

no one can't deal with it,I can't believe it,We need your help,thank you so much @alinz https://github.com/alinz

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/alinz/react-native-webview-bridge/issues/200#issuecomment-272807696, or mute the thread https://github.com/notifications/unsubscribe-auth/AAyekG3jCiVkEWuAsGSqaPO86kAqWPxqks5rSzOhgaJpZM4LdqLG .

--

[image: --]

Avishay Bar [image: https://]about.me/avishayb https://about.me/avishayb?promo=email_sig&utm_source=email_sig&utm_medium=email_sig&utm_campaign=external_links

apeque commented 7 years ago

+1

MacKentoch commented 7 years ago

Hi, I'm not pretending this applies to your issues, but remember that in Android (iOS doesn't care) injected scripts should not contains comments at all.

// a comment like that would prevent injected script to work
// I don't know why but I know I already faced this issue
qq326646683 commented 7 years ago

I‘m regret that I can't get you @avishayil

qq326646683 commented 7 years ago

Have you dealed with it? @erikuix @MacKentoch

MacKentoch commented 7 years ago

@qq326646683 When I have trouble in Android it is always only because of remaining comments.

When I have a huge library to deal with I clean comments with strip-comments then it is ok.

Important: The most advanced RN version I used until now is 0.39.2 (I don't upgrade so often: you all know the pain it can be...).

avishayil commented 7 years ago

Hi @qq326646683, Please check this fork: https://github.com/geektimecoil/react-native-webview-bridge Follow the updated Readme. It works well for me, and also fits RN 0.40.

qq326646683 commented 7 years ago

I can't accept "Edit scripts/WebViewBridgeCustomScript.js and insert your desired custom script, you wish to be injected to the page, instead of using the injectedJavaScript prop of WebView." in Read me,because I need send my data from rn to html by injectedJavaScript. @avishayil

qq326646683 commented 7 years ago
componentWillMount() {
    injectScript = `
    alert(8)

(function () { var data = [[1000,2000,3000,4000,5000,7000,9000]]; var data_max = 10000; //Y轴最大刻度 var line_title = ["A"]; //曲线名称 var y_label = "收入"; //Y轴标题 var x_label = "时间"; //X轴标题 var x = ['2017.4.24','4.25','4.26','4.27','4.28','4.29','4.30']; //定义X轴刻度值 // var title = "周收入"; //统计图标标题 j.jqplot.diagram.base("chart1", data, line_title, "周", x, x_label, y_label, data_max, 1); // j.jqplot.diagram.base("chart2", data, line_title, "这是统计标题", x, x_label, y_label, data_max, 2); }()); `; } result: ios can alert(8),but android can't

qq326646683 commented 7 years ago

Inspired by you,I remove the comment section,then it worked,but it also don't alert at android,I'm curious。In short,thank you very much! @MacKentoch

qq326646683 commented 7 years ago
componentWillMount() {
    injectScript = `

(function () { var data = [[1000,2000,3000,4000,5000,7000,9000]]; var data_max = 10000; var line_title = ["A"]; var y_label = "收入"; var x_label = "时间"; var x = ['2017.4.24','4.25','4.26','4.27','4.28','4.29','4.30']; j.jqplot.diagram.base("chart1", data, line_title, "周", x, x_label, y_label, data_max, 1); }()); `;

MacKentoch commented 7 years ago

@qq326646683 glad you solved. By the way I'm not sure alert work in android.

leesyun commented 5 years ago

@qq326646683 你最后解决问题了吗