我想在 SAP BO“查询生成器”上运行一个脚本片段,它是一个使用 SQL 检索数据的简单工具。 (由于信誉原因,我无法上传图片,产品的界面可以在这里找到:http://scn.sap.com/docs/DOC-42952)
因为我有一堆查询要运行,所以我想使用片段自动运行它们。使用以下代码:
//select the textarea to insert retrieved queries
document.querySelector("textarea").textContent = "SELECT * FROM CI_INFOOBJECTS";
//click the submit button
document.getElementsByTagName('input')[0].click();
//code to export the query result
//after click(), the page reloaded and it won't executed the following code.
document.addEventListener("DOMContentLoaded", function() {
//back to the previous page, run the previous code again
window.history.back(1);
}, false);
有没有人知道如何实现它?感谢您的帮助。
最佳答案
您可以使用 Tampermonkey对于 chrome,您可以从 hibbard tampermonkey tutorial 等网站学习如何使用它. 总体而言,您的脚本将如下所示:
// ==UserScript==
// @name Enter any name you like here
// @namespace URL of website you own
// @version 0.1
// @description retrive data using sql
// @author Your name here
// @match relevant url
// ==/UserScript==
/* jshint -W097 */
// Your code here...
//select the textarea to insert retrieved queries
document.querySelector("textarea").textContent = "SELECT * FROM CI_INFOOBJECTS";
//click the submit button
document.getElementsByTagName('input')[0].click();
//code to export the query result
//after click(), the page reloaded and it won't executed the following code.
document.addEventListener("DOMContentLoaded", function() {
//back to the previous page, run the previous code again
window.history.back(1);
}, false);
关于javascript - 自动运行 JavaScript 脚本片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27699641/