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

x
?
Solved

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

Posted on 2011-10-31
3
Medium Priority
?
283 Views
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?
0
Comment
Question by:paulshin
  • 2
3 Comments
 
LVL 9

Expert Comment

by:djon2003
ID: 37060727
Is the URL passed will be on the same domain or not ?
0
 
LVL 5

Accepted Solution

by:
AlokJain0412 earned 1200 total points
ID: 37060906
0
 
LVL 9

Assisted Solution

by:djon2003
djon2003 earned 800 total points
ID: 37061121
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses
Course of the Month18 days, 11 hours left to enroll

834 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