[英]Check attribute href by jQuery
Let my site be http://cars.com
让我的网站为http://cars.com
I have links on my site, to http://girls.com
, http://google.com
, http://happy.com
, etc. 我的网站上有http://girls.com
http://google.com
: http://happy.com
http://google.com
: http://happy.com
等的链接。
Here is js: 这是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. 因此,当我们单击链接时,它将加载该页面的html。
How to: 如何:
$_SERVER['SERVER_NAME']
on php. 如php上的$_SERVER['SERVER_NAME']
。 href
? 清理属性href
? such symbols like " #, ?
" should be removed 诸如“ #, ?
,?”之类的符号应删除 href
is an url (can be /section/images/
or just /
) to my site ( $_SERVER['SERVER_NAME']
)? 检查这个href
是否是我网站( $_SERVER['SERVER_NAME']
)的网址(可以是/section/images/
或只是/
)? If not, do nothing (don't want to load html of other sites). 如果不是,则不执行任何操作(不想加载其他网站的html)。 Thanks. 谢谢。
location.host
property . 使用location.host
属性 。 Use a regex to parse the string. 使用正则表达式解析字符串。
For example: 例如:
var pathSection = /^[^?#]+/.exec(url)[0]
/^\\w+:/
. 使用正则表达式,例如/^\\w+:/
。 this is not possible for security reasons the restriction is called Same Origin Policy or short SOP. 出于安全原因,这是不可能的,该限制称为“ 相同来源策略”或简称SOP。 You can bypass this by proxying the request via a server side script. 您可以通过服务器端脚本代理请求来绕过此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.