Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript手动单击运行命令,但不在加载时工作_Javascript_Asp.net_React Native_Webforms_React Native Android - Fatal编程技术网

JavaScript手动单击运行命令,但不在加载时工作

JavaScript手动单击运行命令,但不在加载时工作,javascript,asp.net,react-native,webforms,react-native-android,Javascript,Asp.net,React Native,Webforms,React Native Android,我的网页上有锚标签。我喜欢触发点击事件onload。这意味着我想打开React本机应用程序的深层链接“narvin://wallet“转到我的应用程序。如果手动单击,该链接将正常工作 <script type="text/javascript"> function startMyApp() { document.location = 'narvin://wallet'; setTimeou

我的网页上有锚标签。我喜欢触发点击事件onload。这意味着我想打开React本机应用程序的深层链接“narvin://wallet“转到我的应用程序。如果手动单击,该链接将正常工作

<script type="text/javascript">
        function startMyApp() {                
            document.location = 'narvin://wallet';
            setTimeout(function () {
                if (confirm('You do not seem to have Your App installed, do you want to go download it now?')) {

                    document.location = 'https://cafebazaar.ir/app/cab.snapp.passenger';
                }
            }, 300);
        }
</script>
    <a href="#" onclick="startMyApp()" id="loader">Try to start MyApp </a>

函数startMyApp(){
document.location=narvin://wallet';
setTimeout(函数(){
如果(确认('您似乎没有安装应用程序,是否立即下载?')){
document.location=https://cafebazaar.ir/app/cab.snapp.passenger';
}
}, 300);
}
,但不使用此代码在加载页面上工作:

<script type="text/javascript">
            window.onload = function () {
                document.getElementById("loader").onclick();
                setTimeout(function () {                    
                    if (confirm('You do not seem to have Your App installed, do you want to go download it now?')) {

                        document.location = 'https://cafebazaar.ir/app/cab.snapp.passenger';
                    }
                }, 3000);
            };
</script>

window.onload=函数(){
document.getElementById(“loader”).onclick();
setTimeout(函数(){
如果(确认('您似乎没有安装应用程序,是否立即下载?')){
document.location=https://cafebazaar.ir/app/cab.snapp.passenger';
}
}, 3000);
};


window.onload=函数(){
document.location=narvin://wallet';
setTimeout(函数(){
如果(确认('您似乎没有安装应用程序,是否立即下载?')){
document.location=https://cafebazaar.ir/app/cab.snapp.passenger';
}
}, 3000);
};

您的getElementById返回空值,因为您的脚本在加载文档之前执行。加载所有页面内容后,必须调用窗口。您可以使用document.ready事件代替window.onload事件

第三个事件应该运行。第二次运行不会运行,因为您正在调用
onclick
而不是
click
,我认为第三次运行正常,但不起作用。我使用警报逐步进行测试,并在文档前后显示警报。位置=narvin://wallet'; 但命令不起作用。但当手动单击时,它会工作。
<script type="text/javascript">
            window.onload = function () {
                document.location = 'narvin://wallet';
                setTimeout(function () {                    
                    if (confirm('You do not seem to have Your App installed, do you want to go download it now?')) {

                        document.location = 'https://cafebazaar.ir/app/cab.snapp.passenger';
                    }
                }, 3000);
            };
</script>