Web Page App - JavaScript Examples

Overview

The advanced settings in our Enplug Webpage App allow you to use custom JavaScript to log onto websites. Use and customize the snippets below to automize your webpage and log in.

 

Contents of this guide

Accessing Web Page App Advanced Settings

JavaScript Examples:

  1. Generic
  2. Sharepoint
  3. PowerBi
  4. Okta
  5. Microsoft Online
  6. Add Auto-Scroll to a Web Page
  7. Disable a Popup Window

 

Accessing Web Page App Advanced Settings

1. Open the Web Page app

  • Select "Apps" > "All Apps"
  • Select "Web Page"

2. Select an existing web page to edit, or select "Add Web Page"

3. Click "Show Advanced Settings"

mceclip0.png

4. Enter your Javascript and username/password (if required)

mceclip1.png

5. Select "Save"

 

JavaScript Examples

 

1. Generic

These are examples for some generic scripts that may work for your site as-is, or require minimal modification:

document.querySelector("#id__email").value = webView.getUsername();
document.querySelector("#id__password").value = webView.getPassword();
document.querySelector(".login_button").click();

 or

var v1 = document.getElementById('username'); 
v1.value = webView.getUsername();
var v2 = document.getElementById('password');
v2.value = webView.getPassword(); document.getElementById('loginBtn').click();

 

2. Sharepoint:

try {
document.querySelector('#username').value = webView.getUsername();
var next = document.querySelector('form a');
if(next){next.click();}
} catch (e) { }
try {
const pass = document.querySelector('#password');
if (pass) {
pass.value = webView.getPassword();
document.querySelector('form button').click();
}
} catch (e) { }

 

3. PowerBi:

function submit(name, value, koProp) {
return function () {
var el = document.querySelector('div input[name=' + name + ']:not(.moveOffScreen)');
if (el) {
ko.dataFor(el)[koProp].value(value);
return true;
}
}
}
function tryRemembered() {
return new Promise(function (resolve) {
var container = document.querySelector('#tilesHolder');
if (!container) { resolve(false); return; }

ko.dataFor(container).tile_onClick(ko.dataFor(document.querySelector('.tile-container')));
resolve(true);
});
}
function complete(task) {
return new Promise(function (resolve) { schedule(task, resolve); });
}
function schedule(task, resolve) {
setTimeout(function () { tryToComplete(task, resolve); }, 2000);
}
function tryToComplete(task, resolve) {
if (task()) {
document.querySelector(`input#idSIButton9`).click();
resolve();
}
else { schedule(task, resolve); }
}
function tryRedirect() {
const signInRedirect = document.querySelector('a.button');
if (signInRedirect) {
signInRedirect.click();
return true;
}
return false;
}
function tryConfirmRemember() {
const yesBtn = document.querySelector('input#idSIButton9');
if (document.querySelector('input#KmsiCheckboxField') && yesBtn) {
yesBtn.click();
return true;
}
return false;
}

if (!tryRedirect() && !tryConfirmRemember()) {
tryRemembered().then(function (foundLogin) {
var completePassword = function () {
complete(submit('passwd', webView.getPassword(), 'passwordTextbox'));
};
if (foundLogin) {
completePassword();
} else {
complete(submit('loginfmt', webView.getUsername(), 'usernameTextbox'))
.then(completePassword);
}
});
}

 

4. Okta:

function login() {
if ( document ) {
try {
var event = document.createEvent('Event');
event.initEvent('input', true, true);
//'okta-signin-username' is the ID of the field where the Email address will be entered on the page.
document.getElementById('okta-signin-username').value = webView.getUsername();
document.getElementById('okta-signin-username').dispatchEvent(event);
//'okta-signin-password' is the ID of the field where the Password will be entered on the page.
document.getElementById('okta-signin-password').value = webView.getPassword();
document.getElementById('okta-signin-password').dispatchEvent(event);
//'okta-signin-submit' is the ID of the submit button located on the page.
document.getElementById('okta-signin-submit').click();
} catch(error){}
} else {
setTimeout(login, 800);
}
};
login();

 

5. Microsoft Online:

function submit(name, value, koProp) {
return function () {
var el = document.querySelector('div input[name=' + name + ']:not(.moveOffScreen)');
if (el) {
ko.dataFor(el)[koProp].value(value);
return true;
}
}
}
function tryRemembered() {
return new Promise(function (resolve) {
var container = document.querySelector('#tilesHolder');
if (!container) { resolve(false); return; }

ko.dataFor(container).tile_onClick(ko.dataFor(document.querySelector('.tile-container')));
resolve(true);
});
}
function complete(task) {
return new Promise(function (resolve) { schedule(task, resolve); });
}
function schedule(task, resolve) {
setTimeout(function () { tryToComplete(task, resolve); }, 2000);
}
function tryToComplete(task, resolve) {
if (task()) {
document.querySelector(`input#idSIButton9`).click();
resolve();
}
else { schedule(task, resolve); }
}
tryRemembered().then(function (foundLogin) {
var completePassword = function () { complete(submit('passwd', webView.getPassword(), 'passwordTextbox')) };
if (foundLogin) {
completePassword();
} else {
complete(submit('loginfmt', webView.getUsername(), 'usernameTextbox'))
.then(completePassword);
}
});

 

6. Add Auto-Scroll to a Web Page:

function doScroll(body, interval) {
body.animate({ scrollTop: body.scrollTop() + 100 }, interval, 'linear', function () {
setTimeout(function () { doScroll(body, interval) });
});
}
(function run(interval) { doScroll($('html'), interval) })(2500);

 

7. Disable a Popup Window:

Example Website: https://www.dodocase.com/

  • document.querySelector('#justuno_form').remove()
  • document.querySelector('[target=hidden_iframe]').remove()

Example Website: https://www.daniellelaporte.com/

  • document.querySelector('.sqs-popup-overlay').remove()
Was this article helpful?
0 out of 0 found this helpful
Powered by Zendesk