Search code examples
urldrupal-7anchorgoto

Use drupal_goto with named anchor in url


i am trying to go to an location choosen by my script. I'm using url() and drupal_goto() to archive this, but the fragment-option named at the url()-documentation-page seems not working like i understand it or more likely drupal_goto() is changing the link.

The link-string i want should look like:

/topsection/section#subsection

but instead i'm getting the hash-sign encoded like

/topsection/section%23subsection

Here is my code:

$section = url( '/topsection/' . 'section', array( 'fragment' =>  'subsection', 'alias' => TRUE ) );
drupal_goto( $section );

Any help would be nice! Thank you.


Solution

  • Ha! just found the solution:

    I misunderstood the documentation. It is correctly telling that i should use drupal_goto() with fragment/anchor passed as option like i would give to url().

    This is working:

    drupal_goto( '/topsection/' . 'section', 
      array( 
        'fragment' => 'subsection',
        'alias' => TRUE ) );