检测单击链接时,在新框架中打开

我想使用框架创建一个基本的URL重写。

我无法访问.htaccess来执行mod_rewrite

有没有办法使用PHP,jQuery,JavaScript等来检测点击了哪个URL,然后在新框架中打开URL?

例如:用户点击/index.php?12345它将在框架窗口/pages/12345/index.html打开,如果他们点击/index.php?54321将在框架窗口中打开/pages/54321/index.html

我不认为我真的明白你的意思。 通常url重写的工作方式如下:
用户点击了http://example.com/content/example
哪个被重写为http://example.com/index.php?cat=content&page=example

您可以通过将链接设置为http://example.com/index.php/content/example来伪造此效果,网络服务器仍将请求页面index.php,然后您可以在其中读取index.php之后的部分(但在查询字符串之前)

 $_SERVER['PATH_INFO'] 

然后解析它以获得您需要的东西。

PHP.net上的$ _SERVER [‘PATH_INFO’]

包含任何客户端提供的路径名信息,该信息尾随实际脚本文件名但在查询字符串之前(如果可用)。 例如,如果通过URL http://www.example.com/php/path_info.php/some/stuff?foo=bar访问当前脚本,则$ _SERVER [‘PATH_INFO’]将包含/ some / stuff 。

PHP解决方案将是这样的:

 if (!empty($_REQUEST)) { $page = array_pop($_REQUEST); if (is_numeric($page)) { header("Location: pages/$page/index.html"); exit; } } 

如果我真的明白你想要什么,我认为这很容易。

当用户单击它时,调用一个JQuery函数,该函数使用AJAX将链接的内容发送到PHP。 之后,PHP分析链接,获取页面内容(使用include())并通过JSON将其发送到JQuery。

这样的jquery可能会有所帮助,

 jQuery(function($){ //this prevents all link elments' default behaviour //when you click they won't navigate the page $("a").click(function(){ //you get the links href var actual_url = $(this).attr("href"); var new_url = ""; //[write your code here for converting actual url to new one] //and open the new url in the frame you want window.parent.yourFrameName.location = new_url; //necessary for preventing default behaviour return false; }); }); 

思南。

最佳解决方案是使用jquery检查是否访问了链接,然后将链接的目标更改为_blank。

您可以使用此站点的插件: 链接文本 ,然后执行此类代码:

  $('a').visited(function () { $(this).attr('target','_blank'); }); 

我认为这就是你在寻找什么。