Let my site be http://cars.com
I have links on my site, to http://girls.com
, http://google.com
, http://happy.com
, etc.
Here is js:
$("#wrapper a").live('click', function()
{
var this_url = $(this).attr("href");
$.ajax({
url: this_url,
complete: function(){
//do something
}
});
});
So, when we click on a link, it loads html of that page.
How to:
$_SERVER['SERVER_NAME']
on php.href
? such symbols like "#, ?
" should be removedhref
is an url (can be /section/images/
or just /
) to my site ($_SERVER['SERVER_NAME']
)? If not, do nothing (don't want to load html of other sites).Thanks.
this is not possible for security reasons the restriction is called Same Origin Policy or short SOP. You can bypass this by proxying the request via a server side script.
location.host
property.Use a regex to parse the string.
For example:
var pathSection = /^[^?#]+/.exec(url)[0]
/^\w+:/
.