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

Posted on 2014-08-27
Last Modified: 2014-08-27

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"}/* ]]> */

Open in new window

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

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
Question by:badwolfff

    Accepted Solution

    I found it out myself:

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

    Open in new window


    Author Closing Comment

    I found it myself

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now