A href With echo open in a new window - php

I want to open this link on a new window: is the following correct?
Check Your Adress

I Just Find The Way To Open The Link In A New Page The Code Is
<a target = '_blank' href="<?php echo "$link"; ?><?php echo $userRow['user_wallet']; ?>" >Check Your Adress</a>

Use window.open() of javascript to achieve this.
<a onclick="window.open(document.URL, '_blank', 'location=yes,height=700,width=550,scrollbars=yes,status=yes');">Open In New Window</a>
This should help you.

Related

PHP syntax for opening a new tab on click

I need to add target="_blank" property somewhere so that when logos are clicked they are opened in a new tab.
I am working on a website that uses the following PHP code to reference links in logos:
<?php if($cta): ?>
<div class="product-logos-container">
<?php foreach($cta as $_cta): ?>
<span class="card" <?php if($_cta['banner_link']): ?>onclick="window.location.href='<?php echo $_cta['banner_link'] ?>'"<?php endif ?>>
<span class="detail" style="opacity: 0;">
<span class="inner"><?php echo $_cta['banner_title'] ?></span>
</span>
<img src="/clear_cta/<?php echo $_cta['banner_filename'] ?>" alt="<?php echo $_cta['banner_title'] ?>" class="image"/>
......
Now I'm fairly certain that I need to add target="_blank" to the 4th line. I'm not sure which syntax is right for it, and after doing some research I'm starting to think that window.location might be the problem. If so please advise an alternative code that would open links when clicked in new tabs.
Use window.open instead of window.location
window.open('<?php echo $_cta['banner_link'] ?>',
'_blank' // <- This is what makes it open in a new window.
);
Only we can use target="_blank" inside anchor tags () to tell the browser where the linked document should be loaded.
Try This
1
<span>
See my portfolio
</span>
2
<a target = '_blank' href=view_rfp_detail.php?sna=$sna >$sna</a>
In Your case this is more of a JavaSript problem. The important part is
window.location.href=something
It is very complicated to open a new window or tab from JavaScript. This is the infamous popup. The browser started to block it by default long time ago.
You can try to rewrite this part
<span class="card" <?php if($_cta['banner_link']): ?>onclick="window.location.href='<?php echo $_cta['banner_link'] ?>'"<?php endif ?>>?>onclick="window.location.href='<?php echo $_cta['banner_link'] ?>'"<?php endif ?>>
Into something like
<a class="card" <?php if($_cta['banner_link']): ?>href="<?php echo $_cta['banner_link'] ?>" target="_blank"<?php endif ?>>
and change the closing tag too.

Back one directory in php

I am building a wordpress site with galleries in it and want to add a 'Back to Gallery' link in my single-attachment.php that will send the user back one directory.
For example, if the image is at www.site.com/galleries/gallery1/image1/ I would want the link to send it back to www.site.com/galleries/gallery1/.
Any suggestions would be appreciated.
You can either explode current URL,and remove last term from the URL and give it as link for Back to Gallery.
<?php $url = explode('/', 'www.site.com/galleries/gallery1/image1/');
array_pop($url);
$back=implode('/', $url);
?>
<a href="<?php echo $back; ?>" >Back to Gallery</a>
Or you can use $_SERVER['HTTP_REFERER'] for getting the previous URL.
<a href="<?php echo $_SERVER['HTTP_REFERER']; ?>" >Back to Gallery</a>
also by using javascript you can implement this in easy way :
<a href="javascript:history.go(-1)" >Back to Gallery</a>

Make a php a href link with variable clickable

i have a question.
I have this code to get an profile name as an link.
<a href=<?php echo $userpro->permalink( get_the_author_meta('ID') );
?>><?php echo $user_id=get_the_author_meta('display_name');?></a>
The link isnt clickable. I am a newbie in coding.
So maybe somebody can help me :)
Greetings
Try this:
<a href="<?php echo $userpro->permalink(get_the_author_meta('ID')); ?>">
<?php echo get_the_author_meta('display_name'); ?>
</a>
If it doesnt work... please supply the value and initialisation of $userpro!

CSS & PHP; Add URL inside

<?php $picNumberSlide = "<div id='slidenumber'></div>" ;?>
Num Print
<div id="slidenumber"></div> -> (Picture slide number)
Link
<a href="share?picNum=<?php echo $picNumberSlide;?>">
Not work.
<div id='slidenumber'></div> slide number of the screen writes.
I intended to write inside the URL's
How i can do? Thank you!
(i sorry for Eng)
<?php $picNumberSlide = "<div id='slidenumber'></div>" ;?>
The above defines the $picNumberSlide variable as a div.
<a href="share?picNum=<?php echo $picNumberSlide;">
Here you are placing a div inside the href of an anchor, that will never work.
You need to assign the $picNumberSlide variable only the number you wish to use.
Then using
<a href="share?picNum=<?php echo $picNumberSlide; ?>">
will work.
$picNumberSlide should only = a number
Change <a href="share?picNum=<?php echo $picNumberSlide;">
To <a href="share?picNum=<?php echo $picNumberSlide;?>">
(You were missing the closing tag for php)

CodeIgniter - Correct way to link to another page in a view

I was wondering if someone could tell me the correct way to link to another page from within a view.
Is there a function for this or is it just the usual about
I assume you are meaning "internally" within your application.
you can create your own <a> tag and insert a URL in the href like this
Link
OR you can use the URL helper this way to generate an <a> tag
anchor(uri segments, text, attributes)
So... to use it...
<?php echo anchor('controller/function/uri', 'Link', 'class="link-class"') ?>
and that will generate
Link
For the additional commented question
I would use my first example
so...
<img src="<?php echo base_url() ?>img/path/file.jpg" />
for images (and other assets) I wouldn't put the file path within the PHP, I would just echo the base_url() and then add the path normally.
The best way is to use the following code:
Link
you can also use PHP short tag to make it shorter. here's an example
<a href="<?= site_url('controller/function'); ?>Contacts</a>
or use the built in anchor function of CI.
Best and easiest way is to use anchor tag in CodeIgniter like eg.
<?php
$this->load->helper('url');
echo anchor('name_of_controller_file/function_name_if_any', 'Sign Out', array('class' => '', 'id' => ''));
?>
Refer https://www.codeigniter.com/user_guide/helpers/url_helper.html for details
This will surely work.
you can also use this code
//test" class="btn btn-primary pull-right">
<a href="<?php echo site_url('controller/function'); ?>Compose</a>
<a href="<?php echo site_url('controller/function'); ?>Inbox</a>
<a href="<?php echo site_url('controller/function'); ?>Outbox</a>
<a href="<?php echo site_url('controller/function'); ?>logout</a>
<a href="<?php echo site_url('controller/function'); ?>logout</a>

Categories