1

I have a javascript code on index.php calling a page like this :

   id = 5;
   var url = 'pages/pg/'+id+'/';
    f.action  = urlss.toLowerCase();
   return true;

the problem is that when I am landing at that page and want to call again with a different ID id doesn't work , I must provide var url the entire path :

var url = 'mysite.com/pages/pg/'+id+'/';

is there a way to call it without http domaine ?

2 Answers2

0

You're using relative url say (i figure out) from your website root (/).

When you navigate to pages/pg/<id> you are in fact navigating to /pages/pg/<id>. That is: <id> page in /pages/pg web directory so your new current path is /pages/pg and hence navigating to pages/pg/<id> you are in fact navigating to /pages/pg/pages/pg/<id> (see url field of your browser...).

Whenever possible I strongly advice you to always use absolute url's if you can.

Otherwise you should take care of any path change to properly fix your relative paths.

bitifet
  • 3,514
  • 15
  • 37
0

Change the window.location property

You can set the absolute url: window.location="http://www.google.es"

The relative path to the current url viewed: window.location="./relativePath"

Or the relative path to the current domain: window.location="/domainRelative"

This another answer explains the absolute vs relative paths https://stackoverflow.com/a/21306605/4635829

bitifet
  • 3,514
  • 15
  • 37
jmtalarn
  • 1,513
  • 1
  • 13
  • 16