“Campaigns have been buying advertising on television for 40-plus years now; they’ve only been buying ads on the Internet for three or four years,” said Mindy Finn, director of Mr. Romney’s online strategy. “It’s more uncharted territory, and everyone’s trying to figure it out.”

Television is still the primary means by which the campaigns reach voters by the millions, and even now, Internet advertising makes up a small fraction of the candidates’ advertising budgets.

But campaign strategists say the Internet provides unrivaled opportunity to draw volunteers and donations for mere pennies, through Web sites that often make their interests and affiliations clear. (The campaign of Senator John McCain, Republican of Arizona, knows, for example, it is talking to veterans when advertising on Military.com.)

Still, the Romney campaign had not expected its banners to appear on FanFiction.net, whose users have seen thousands of “Romney for President” ads while using the site to write their own plots about their favorite fictional characters — or read the work of others, including pornographic scenes between Harry Potter and Hermione Granger.

And Mr. Romney’s aides said they did not know their ads had run on Gay.com or FanFiction.net.

Mr. Romney is not the only presidential candidate still finding his way online.

Earlier this year, Senator Barack Obama, Democrat of Illinois, removed an advertisement from an Amazon.com screen dedicated to the book “The Israel Lobby and U.S. Foreign Policy,” which has upset Jewish groups who view it as anti-Semitic — learning it was there only when contacted by The New York Sun. A former aide to Mr. McCain said he was surprised to see his candidate’s ads appear on the liberal Huffington Post Web site.

Last week an ad for Rudolph W. Giuliani, the former New York mayor who is trying to overcome conservative suspicion in the race for the Republican presidential nomination, showed up on a liberal blog, DailyKos.