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

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?
paulshinAsked:
Who is Participating?
 
AlokJain0412Commented:
0
 
djon2003Commented:
Is the URL passed will be on the same domain or not ?
0
 
djon2003Commented:
Same domain :
Put the URL into an IFRAME and use :
var iFrameDoc = $("#myIframe").get(0).contentWindow.document;
var scripts = iFrameDoc.scripts;
var siteToMatch = /google.com/m;

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)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.