jQuery技术:检测单击链接时,在新框架中打开

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

我无法访问.htaccess来执行mod_rewrite

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

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

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

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

     $_SERVER['PATH_INFO'] 

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

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

    包含任何客户端提供的路径名信息,该信息尾随实际脚本文件名但在查询字符串之前(如果可用)。 例如,如果通过URL _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'); }); 

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

      以上就是jQuery教程分享检测单击链接时,在新框架中打开相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/558385.html

      (0)
      上一篇 2021年1月26日
      下一篇 2021年1月26日

      精彩推荐