cordova inappbrowser 引用元素
cordova inappbrowser referencing elements
有什么方法可以使用 cordovas InAppBrowser 来引用页面上的元素并检测它们何时被按下?我引用的页面有一个后退按钮和一个关闭按钮,我需要知道按下了哪个按钮,然后关闭 inAppBrowser。
我假设它看起来像这样,但我似乎无法让它工作
var ref = window.open(url, '_blank');
ref.addEventListener('loadstop', function(event) {
ref.executeScript({
code:
"document.getElementById('pageHeader').onclick = function() {
alert('button was clicked');
}"
});
}
是否可以改用:
executeScript({ link: "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" });
然后使用jQuery?
executeScript({ code: "$('#pageHeader').on('click', function() { alert('button was clicked'); }"});
我刚刚在 iOS 上检查过,它正在运行,你的语法有误
在 bing 网站 sbBtn
上注入 js 的工作示例是搜索图标按钮:
var ref = window.open("https://www.bing.com/?setlang=es", '_blank');
ref.addEventListener(
'loadstop',
function(event) {
ref.executeScript({
code: "document.getElementById('sbBtn').onclick = function() {alert('button was clicked');}"
});
}
);
以及 jquery 方法:
var ref = window.open("https://www.bing.com/?setlang=es", '_blank');
ref.addEventListener('loadstop', function(event) {
ref.executeScript({
file: "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"
}, function() {
ref.executeScript({
code: "jQuery('#sbBtn').on('click', function() { alert('button was clicked'); });"
});
});
});
有什么方法可以使用 cordovas InAppBrowser 来引用页面上的元素并检测它们何时被按下?我引用的页面有一个后退按钮和一个关闭按钮,我需要知道按下了哪个按钮,然后关闭 inAppBrowser。
我假设它看起来像这样,但我似乎无法让它工作
var ref = window.open(url, '_blank');
ref.addEventListener('loadstop', function(event) {
ref.executeScript({
code:
"document.getElementById('pageHeader').onclick = function() {
alert('button was clicked');
}"
});
}
是否可以改用:
executeScript({ link: "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" });
然后使用jQuery?
executeScript({ code: "$('#pageHeader').on('click', function() { alert('button was clicked'); }"});
我刚刚在 iOS 上检查过,它正在运行,你的语法有误
在 bing 网站 sbBtn
上注入 js 的工作示例是搜索图标按钮:
var ref = window.open("https://www.bing.com/?setlang=es", '_blank');
ref.addEventListener(
'loadstop',
function(event) {
ref.executeScript({
code: "document.getElementById('sbBtn').onclick = function() {alert('button was clicked');}"
});
}
);
以及 jquery 方法:
var ref = window.open("https://www.bing.com/?setlang=es", '_blank');
ref.addEventListener('loadstop', function(event) {
ref.executeScript({
file: "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"
}, function() {
ref.executeScript({
code: "jQuery('#sbBtn').on('click', function() { alert('button was clicked'); });"
});
});
});