FANDOM


This Forum has been archived

Visit the new Forums
Forums: Index Help desk Automatic text edit on page load?
FANDOM's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.

50px-Replacement filing cabinet.svg

Note: This topic has been unedited for 3795 days. It is considered archived - the discussion is over. Do not add to unless it really needs a response.

If one wanted to configure some JavaScript so that it would always first check if there was a piece of code in the wiki source, and if it is not present, plug it in on edit, how would one do that? For instance, when someone goes to "action=edit", check if the text box has "fooBar, Quok.", and if it doesn't, add it to the end of the page. What would the JavaScript for this look like? (sorry, every time I try scripting, I phail...) TimerootTCE 09:50, 30 June 2009 (UTC)

As starting point:
if (wgAction == 'edit' || wgAction == 'submit') {
	$(appendWikiText);
}

function appendWikiText(){
	var tb = document.getElementById('wpTextbox1');
	var text = "fooBar, Quok.";
	if (tb && tb.value.indexOf(text) == -1) {
		tb.value += text;
	}
}
--Ciencia Al Poder (talk) -WikiDex 18:18, 30 June 2009 (UTC)
Community content is available under CC-BY-SA unless otherwise noted.