How to Call an OnBlur Method from a Chrome Extension

Tallima

I'm working on a Chrome extension that simply makes an owner account text box the same as a scheduling account textbox. The text boxes have onblur methods on the original website that, through a round-about way after calling many functions, save the data to the server.

When I change one text box, I set the other text box's value. That works visually. But the data is not saving to the network for the textbox I don't actually click on. (OwnerAccount is updated, Scheduling Account is not)

var tbOwnerAccount = document.getElementById("ctl00_ContentPlaceHolder1_txtOwnerAccountNumber");
var tbSchedulingAccount = document.getElementById("ctl00_ContentPlaceHolder1_txtSchedulingAccountNumber");

tbSchedulingAccount.value = tbOwnerAccount.value;

But now it's time to save the value to server. I thought simply blurring the scheduling account would call the onblur() method of tbSchedulingAccount. No dice.

tbSchedulingAccount.blur();

I also tried:

tbSchedulingAccount.focus();
tbSchedulingAccount.select();
tbSchedulingAccount.value = tbOwnerAccount.value;

(with and without a blur at the end -- the user will naturally click somewhere, so if I can get the cursor in the tbSchedulingAccount textbox, it should blur on its own)

I tried calling the function using the Chrome console, and it works:

tbSchedulingAccount.onblur();

but I can't get it to actually blur out and call the function using tbSchedulingAccount.blur();

If it's any help, here's the element I'm trying to blur:

<input name="ctl00$ContentPlaceHolder1$txtSchedulingAccountNumber"
type="text" maxlength="25" id="ctl00_ContentPlaceHolder1_txtSchedulingAccountNumber"
tabindex="9" class="textbox" onblur=" MASSIVE PROPRIETARY FUNCTION"
onkeydown="javascript:if(event != null &amp;&amp; event.keyCode == 13){ 
MASSIVE PROPRIETARY FUNCTION" style="width:200px;">

So, my main question is:

  • Can I call the onblur function from an extension when another textbox loses focus?

(I should note, the textbox I want to call the function from (tbOwnerAccount) has an onblur in the original website that I can't mess with or it won't save to the server)

Here's all of my code so far:

var tbOwnerAccount = document.getElementById("ctl00_ContentPlaceHolder1_txtOwnerAccountNumber");
tbOwnerAccount.onblur = updateSchedule;

function updateSchedule(){
    var tbOwnerAccount = document.getElementById("ctl00_ContentPlaceHolder1_txtOwnerAccountNumber");
    var tbSchedulingAccount = document.getElementById("ctl00_ContentPlaceHolder1_txtSchedulingAccountNumber");

    console.log("Fired");

    <CODE FOR THE ORIGINAL WEBSITE'S .ONBLUR ON tbSchedulingAccount TO FIRE>

}

Thanks for any help you can provide!

wOxxOm

Try dispatching blur event:

tbOwnerAccount.dispatchEvent(new Event('blur'))

Or run onblur() directly in an injected DOM-script:

runDOMscript(function() {
    document.getElementById("ctl00_ContentPlaceHolder1_txtOwnerAccountNumber").onblur();
});

function runDOMscript(fn) {
    var script = document.head.appendChild(document.createElement('script'));
    script.text = '(' + fn + ')()';
    script.remove();
}

See Inject code in a page using a Content script that explains differences between contexts of page code and content script code and shows how to run code in page context.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to read file from chrome extension?

How to call the method in watchkit extension from parent ios app

Ambiguous extension method call

How to call a toplevel function from a method or an extension function of the same signature?

How to call a function from an extension to UIViewController in Swift

How to call functions & variables from other JS files in panel - Chrome Extension

How to call an extension method to remove an item from an array

Kotlin: How to call a method with the same name in an extension?

How to release chrome extension from GitHub repository

How to call method from services?

Call extension method from Javascript Visualforce

Chrome Extension Script not Running in popup (Cannot call method 'addListener' of undefined )

Send text with post method from chrome extension

How call dll from unpaked extension directory

For chrome extension, how can main.js call function from popup.js?

Call a function in chrome extension from a website

How do I call a C# extension method from F#, without open?

Connecting to SignalR from Chrome extension - error: method could not be resolved

How to access host from chrome extension

Chrome Extension Call Function from Injected Script

How to call a javascript function of the page from chrome extension?

How to access an iframe from chrome extension?

call inject.js method from popup.js chrome extension

How To Call Chrome Extension Function After Page Redirect?

How can I call this type of extension method from another class

How to call AAD graph from Ibiza extension

c# how to call an Action from generic extension method in another class

Kotlin: How to call super implementation of an extension method

In the background script for a chrome extension, how does a call to the addListener() method for the chrome.runtime.onInstalled event get processed?