How do I use jquery to test for a script or element in the head of a page?

Posted on 2011-10-31
Last Modified: 2013-11-19
I want to create a page that takes one input, a URL, and then reads the page referenced in the URL and checks a few things:
Is there a script tag in the head whose SRC contains a link to a given site?
Are there any divs in the body whose class name beginx with xyz?

So basically it would be  a form with a text field and a submit button. The generated page would be a report listing the existence or absence of the items in the list above.

Is this something jquery could do?
Question by:paulshin
    LVL 9

    Expert Comment

    Is the URL passed will be on the same domain or not ?
    LVL 5

    Accepted Solution

    LVL 9

    Assisted Solution

    Same domain :
    Put the URL into an IFRAME and use :
    var iFrameDoc = $("#myIframe").get(0).contentWindow.document;
    var scripts = iFrameDoc.scripts;
    var siteToMatch = /;
    for(var i = 0; i < scripts.length; i++) {
      if (scripts[i].src ~= siteToMatch) {
        //DO SOMETHING
    var classToMach = "xyz";
    var divs = jQuery([]).pushStack( iFrameDoc.getElementsByTagName("div") ).filter("className ^=" + classToMatch);

    Open in new window

    Other domain :
    Use the $.get function to retrieve the page. Into the callback function use regular expressions to find what you need.
    (Mostly as suggested by AlokJain)

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now