PhoneWagon DNI supports swapping phone numbers in dynamic HTML. To facilitate this we exposed a JS function that you can call to swap a number on an element in the page. The function is available in the swap.js Snippet.

To find the Snippet, Go to "Numbers" On the left side, Select the company you want the code for in the top right and click "Copy Web Snippet"

Take that Code and place it before the </body> tag of your website's source code.

Below are details of the new function that you can call to handle phone numbers as a result of dynamic HTML

window.pw_dni.swap(<dom element>, <successCallback>, <errorCall back>);

successCallback() : optional
Called when the element is successfully swapped

errorCallback() : optional

Called when there is any error either from coming api or by bad element detection.


Example code with callbacks:

// 1. Swapping with callbacks
// Get a DOM element to perform number swapping
const element = document.getElementById("my-dynamic-div");
if (window.pw_dni) {
// Swapping may happen synchronously or asynchronously
// Use callbacks if you need some code to run after swapping
window.pw_dni.swap(element, function() {
// Success: numbers were swapped in element
}, function() {
// Error: numbers were not swapped
});
}

Example code without callbacks:

// 2. Swapping without callbacks
// Get a DOM element to perform number swapping
const element = document.getElementById("my-dynamic-div");
if (window.pw_dni) {
// I you don't need additional processing after swapping, or error handling,
// you can omit callbacks
window.pw_dni.swap(element);
}

Did this answer your question?