[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Jquery how to find a string in the source code of a page?

Hi,

I two identical pages that are generated by my CMS when I check the sourcecode I see there is ONLY one difference.

Page a.html
<script type='text/javascript'>
/* <![CDATA[ */
var userSettings = {"url":"\/","uid":"2"}/* ]]> */
</script>

Open in new window


Page b.html
<script type='text/javascript'>
/* <![CDATA[ */
var userSettings = {"url":"\/","uid":"5"}/* ]]> */
</script>

Open in new window


I need to get jQuery to identify on pageload which page has the string "uid":"5" in it's sourcecode.
A clue: this code is found in the <head> of the page.

How do I do this?

thanks in advance
0
badwolfff
Asked:
badwolfff
  • 2
1 Solution
 
badwolfffAuthor Commented:
I found it out myself:

if ((jQuery("script:contains('\"uid\":\"5\"')").length) == 1)
{
    alert("yes")
}

Open in new window

0
 
badwolfffAuthor Commented:
I found it myself
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now