/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Regular Expression or searching in Strings Problem

Hi everybody, ?
want to write a funktion that tells my script which page of the website is actually displayed to the user. I decided to use a string search to search keywords in the page title. But to do the searching you have to use regular expressions as search parameters, and that don’t worked out quite well on my site. I only got back not founds from my searches. I think i’m doing something wrong with the regular expression… may be! ?

Here’s the script:

[CODE]
function checkSiteNameTest () {
var found = new Boolean(false);
var searchString = ‘/Test/’;

if (document.title.search(searchString) != -1) found = true;

alert(‘searchString= ‘+searchString+’, title= ‘+document.title+’, document.title.search= ‘+document.title.search(searchString)+’, found= ‘+found);
}[/CODE]

This is the output of the alerts:
searchString= /Test/, title= Search Test , document.title.search=-1, found=false

Greets

Jens

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@DokAug 15.2007 — that tells my script which page of the website is actually displayed to the user[/QUOTE]I would use cookies for that purpose (or some server side mechanism)

But here are some corrections
[CODE]function checkSiteNameTest () {
// Unnessesary construct
// var found = new Boolean(false);
// Instead do
var found = false;
// Regex is wrongly defined as string
// var searchString = '/Test/';
// Should be defined as
var searchString = /Test/;
if (document.title.search(searchString) != -1)
found = true;
alert('searchString= '+searchString+', title= '+document.title+', document.title.search= '+document.title.search(searchString)+', found= '+found);
}[/CODE]
Copy linkTweet thisAlerts:
@jens1701authorAug 16.2007 — Hi Dok, ?

thanks for the correction.

Now i am able to search in Strings. ?

I would use cookies for that purpose (or some server side mechanism)[/QUOTE]
Sure, but you have to store the reference in that cookie in the first place. So you need a function to do that...

What are these serversite mechanisms you where talking about?

By the way i am not able to use php or jsp with the server i'm on.

Only ssi, haven't checked if cgi works jet.

Greets

Jens
Copy linkTweet thisAlerts:
@DokAug 16.2007 — What are these serversite mechanisms you where talking about?[/QUOTE]I always use PHP sessions - they are easy to work with.
×

Success!

Help @jens1701 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...