通过javascript处理URL更改 [英] Handle url change by javascript

查看:74
本文介绍了通过javascript处理URL更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也可以做同样的事情,当网页上的某个链接被点击以获取新的URL并以某种方式处理它时,是否可以处理URL更改?东西,但在我的网页内的一些iframe?我知道如果iframe中的url不在我的域上,我不能在iframe上执行任何JavaScript,但也许可能只是获取iframe的新挂起url。

如果第二个问题需要服务器端解决方案,那么最准确和最恰当的解决方案是什么?

>解决方案

如果您希望所有链接都由JavaScript处理,最好使用JS库。

例如,与jQuery:

  $(a)。click(function(){
var link = $(this ).attr(href);
/ *在这里你的函数
在这个例子中,我只是跟着链接。* /
document.location = link;
return假;
});

我不认为您可以捕获源自其他域的iframe中的事件。 p>

Is it possible to handle URL change when some link on web page is being clicked to get the new URL and somehow process it?

Also can I do the same thing but on some iframe inside my page? I know that I can't execute any javascript on iframe if it's url is not on my domain, but maybe it's possible to just get the new pending url of iframe.

If the second problem requries some server-side solutions then what is the most accurate and right one?

解决方案

You better use a JS library if you want all your links to be handled by JavaScript.

E.g. with jQuery:

$("a").click(function(){
  var link = $(this).attr("href");
  /* Here your function
  In this example I'm just following the link. */
  document.location=link; 
  return false;
});

I don't think you can capture events from an iframe having its source on another domain.

这篇关于通过javascript处理URL更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆