欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Drupal: Creating anchor only link with l()

shiping1 的头像
l('link', '', array('fragment' => 'namedanchor'));

正确答案

 
37down voteaccepted

If you want to create a link with just the fragment, you need to "trick" the url function a bit. As it will append the basepath to all internal urls, '' will become http://example.com.

What you need to do is to set the external option to true:

l('link', '',  array('fragment' => 'namedanchor', 'external' => TRUE));

This will give the desired

<a href='#namedanchor'>link</a>

Alternative you could give the full url like Jeremy suggests.



来自 http://stackoverflow.com/questions/1698453/drupal-creating-anchor-only-link-with-l



 

正确答案
If you could not use clean "#" with fragment, I would suggest you to use <a href="javascript:">link</a>.
When adding "javascript:" or "javascript:void(0)" to href attribute, the <a> tag will do nothing. Then you can bind "onclick" to the link for your ajax purpose.
You can implement this using l() function as below:

     l('link', 'javascript:',  array('external' => TRUE));


来自 http://drupal.stackexchange.com/questions/51596/how-to-create-an-empty-anchor-only-link-with-l 


How do I get the full URL of the current page?

 

I need to get the full URL of the currently opened page. I use the following code, but it returns http://localhost/mysite/page_name.

$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
$link = url($path, array('absolute' => TRUE));

It's not enough for my code to complete; I want to get the values that are passed with the URL as http://localhost/mysite/page_name/value1=value&value2=value.

How can I do that?

正确答案
 

 
20down voteaccepted

Have you tried using request_uri()?

$_SERVER['HTTP_HOST'] . request_uri();

It should do the trick. I haven't tried it myself, and I may be off a bit, but I suggest you give a try. From JavaScript, you could use the window.location.href variable.

来自 http://drupal.stackexchange.com/questions/27880/how-do-i-get-the-full-url-of-the-current-page

 

l(t('View Map & Directions'), $map_address_url, array('attributes' => array('target'=>'_blank')))


普通分类: