Jquery search text in iframe

iframe, jquery, search, string

Solution

You could try:

$("#com").contents();

Note that `$.contents()` can only be performed on an iframe that originates from the same domain due to Same Origin Policy.

So that you could use it to display alert:

if($("#com").contents().text()search("someText")!=-1){
    alert("found");
}

Problem

Can anyone help? i want to search a string inside an iframe like for example. i have a page called main.html which has an iframe and the contents of the iframe(somesite.com) has a string inside lets say "Home". what i want to happen is to have a script that will search the string "home" inside the iframe "#com" and will alert a message stating the string is found. i want this to be done with jquery and not with server side scripting. please note that somesite.com is an external site and i have no control over it. main.html: ``` <html> <body> <input type="button" id="search" value="search"> <iframe id="com" src="http://somesite.com"></iframe> </body> </html> ``` somesite.com ``` <html> <body> Home </body> </html> ``` sorry for the bad english, just comment if you have some clarifications.

Original source

Related problems