href onclick javascript right click - javascript

I have a function in JavaScript something like
function continents(post_id,continent,countries){
location.href="/serv/continent.php?param="+post_id+"&"+continent+"/"+countries;
}
and then I have a anchor tag in my php page
<a href="javascript: void(0)" onclick="continents('<?php echo $row['sno']; ?>','<?php echo $url_con_name; ?>','<?php echo $url_contries; ?>')" >
<div>some date here </div>
</a>
Now the link is working fine but when I right click on that link I don't find open link in new tab and open link in new window.
How can I solve this without removing the function.

There is no href attribute in your a tag, therefore there is no link to open.
The fix is to put a proper URL in your href attribute.
Since you are using jQuery, you likely shouldn't be using onclick attributes anyways.
Do something like this:
<a href="http://example.com/proper/link" id="myLink">
Then attach the JS logic via jQuery:
$('#myLink').click(function(e){
e.preventDefault()
// this will prevent the link from loading the
// href value upon click, but still leave it
// accessible to right-click contextual menu.
the rest of your JS logic here...
})

Add href="#" and onclick event has return false;
Try
<a href="#" onclick="continents('<?php echo $row['sno']; ?>','<?php echo $url_con_name; ?>','<?php echo $url_contries; ?>'); return false;" >
<div>some date here </div></a>

Related

How I can hide or change a url in anchor tag?

when i click on this link the url on page.php is http://localhost/1/page.php?id=1&edition=muzzaffarabad&dt=09-08-2017. i want that after passing these parameters only edition name will show on url .like http://localhost/1/muzzaffarabad
this is anchor tag i m using
<a class='imgFrame' href='page.php?id=1&edition=muzzaffarabad&dt=<?php echo $paper_set["muzzaffarabad_date"]?>'>
Just make your a tag like this:
<a onclick="changeHref()" class='imgFrame' href='page.php?id=1&edition=muzzaffarabad&dt=<?php echo $paper_set["muzzaffarabad_date"]?>'>
Then in your javascript file add function
function changeHref() {
$(".imgFrame").attr("href", "http://localhost/1/muzzaffarabad");
}

file_get_contents not working in a dynamic js call

So, I have been given an admin built in php and I was asked to implement an already done admin built in aspx into the new one(changing the css and so), the thing is that i want to dynamically "insert" into the main admin structure which is made in php only the part that's gonna be run in aspx, I made a reserach and found out that the way to do it was using file_get_contents and yeah it works, the thing is that i want that to show after I click on a link so I put the f_g_c into a js function to do so, the thing is that it doesnt work, it doesnt insert anything, it does it outside a function, but inside it just won't
<li class="active">
<a id="solicitud" href="" >
<i class="fa fa-file-text-o"></i>
<span>Solicitudes</span>
<span class="label label-primary label-circle pull-right">2</span>
</a>
var li = document.getElementById('solicitud');
li.onclick = aparecer();
function aparecer() {
<?php
$hola= "./solicitudAAA.aspx";
?>
var lo = document.getElementById('container');
lo.innerHTML ="<?php echo file_get_contents($hola); ?>";
return false;
}
above there are the section of code or well the link i want to click so it shows the aspx and the second section of code is the actual script, i don't know what I'm doing wrong and why inside the scriptit won't work, thanks for your answers!
The problem with your code has something to do with your link's href. A blank href in your anchor tag will refresh the page causing the onclick in your script to not work. How about adding the following:
<a href="javascript: void(0)" id="solicitud" onclick="aparecer();">
<i class="fa fa-file-text-o"></i>
<span>Solicitudes</span>
<span class="label label-primary label-circle pull-right">2</span>
</a>
To make things easier, add the function to the onclick attribute of the anchor tag to call the function rather than coding it inside the script.
Since onclick attribute(that contains the calling of function) is added to the anchor tag, you can remove this in the script:
var li = document.getElementById('solicitud');
li.onclick = aparecer();
I hope this helps!

PHP How to open 2 links from one click "_self "and "_blank" different url's

So I was wondering how I can code a button to open 2 url's. I have seen retailmenot.com do it when clicking on the button "Get Deal". It opens a new tab with the their article inside their own website but on the original tab it's open a link to the deal site. eg. click on "Get Deal" here http://www.retailmenot.com/view/bestbuy.com
So my code I have done is
<!-- Author -->
<span class="mix-author"></span>
<a attr="<?php echo $item->author_email; ?>" href="<?php echo $website_url; ?>" target="_blank" style="background-color: grey;padding: 5px 7px;border-bottom: 4px ;border-radius: 4px;float: right;color: white;" >GET DEAL</a>
<?php } ?>
The above code opens in a new tab. but I want it to open in the current tab while I want the code(link) below to open in the new tab without showing me the title when the above "GET DEAL" is clicked.
<?php if ($params->get('show_title')) { ?>
<!-- Title -->
<h3>
<?php echo $item->main_title; ?>
</h3>
<?php } ?>
Please help me out.
I think you need to write a javascript function that does both and gets called on the button click:
function twoLinks(same_page_url, new_window_url)
{
window.location = same_page_url; // this will open in the current window
window.open(new_window_url); // this will open in a new window
}
and then call it like so from your link:
<a attr="<?php echo $item->author_email; ?>" href="javascript:void(0);" onclick="twoLinks('<?php echo $website_url; ?>', '<?php echo $new_window_url; ?>');" style="background-color: grey;padding: 5px 7px;border-bottom: 4px ;border-radius: 4px;float: right;color: white;" >GET DEAL</a>
I borrowed from this answer for part of mine:
jQuery: go to URL with target="_blank"
Regarding your further comments, everything works for me as expected when I try your code. Inspect the html in the browser, and your GET DEAL link should contain something like:
<a attr="" href="javascript:void(0);" onclick="twoLinks('http://www.arg.is', 'http://www.google.com');" style="background-color: grey;padding: 5px 7px;border-bottom: 4px ;border-radius: 4px;float: right;color: white;">GET DEAL</a>
I need to see error messages and/or the rendered html of your link to help you. I'm thinking either:
You aren't included the http:// part like I have, and your link is trying a relative path that doesn't exist on your server
One of your variables you're printing into the function parameters isn't what it should be

how to load page in div onclick in yii?

I want to load a page in a certain div by using jquery function .load(), here is my code:
<a href="" onclick="return false;" id="generalinfo">
<div class="row alert alert-danger">
<h4 class="text-center">General Info</h4>
</div>
</a>
<div class="col-lg-6" id="userbody"></div>
<script>
$(document).ready(function(){
$('#generalinfo').click(function(){
$('#userbody').load('<?php echo Yii::app()->basePath."/views/users/_generalinfo.php"; ?>');
});
});
</script>
the page didn't load in the div and there are no errors appeared, so where is the problem here?
instead to execute:
$('#userbody').load('basePath."/views/users/_generalinfo.php"; ?>');
try to call:
$('#userbody').load('http://yousthost:portno/views/users/_generalinfo.php');
The jquery cannot evalutes on client side the PHP code echo Yii::app()->basePath
Try for instance to save the content of the PHP basepath server side in a javascript variable and the use it, like
$('#userbody').load(basePath + '/views/users/_generalinfo.php');
while on the server side, while building the html in the javascript section write:
var basePath = echo Yii::app()->basePath;
hope it's usefull

Inserting content in tinymce, additional text is placed inside inserted content

I've got a video upload for tinymce, which inserts some code into the editor like so:
var content2 = "<div class='playvideo' id='<?php echo $randomnumber;?>'>
<img class='posterimage' src='<?php echo $new_image_path; ?>'>
<a id='<?php echo $new_file; ?>' class='videoplaceholder'></a>
</div></div>";
parent.tinyMCE.execCommand('mceInsertContent', false,content2);
this works fine, and outputs this :
<p><div id="581827" class="playvideo">
<img class="posterimage" src="/uploads/videos/images/1097VID.jpg" alt="" />
<a class="videoplaceholder" id="1097VID.mp4"></a>
</div></p>
But after this content is inserted, ofcourse I would like to continue writing text. But when I do that, the text gets placed inside my inserted content after the img tag.
like so:
<p><div id="581827" class="playvideo">
<img class="posterimage" src="/uploads/videos/images/1097VID.jpg" alt="" />text i try to write goes here for some reason
<a class="videoplaceholder" id="1097VID.mp4"></a>
</div></p>
Fiddle example
When enter is clicked for new line, it creates a second div with the same class as what I inserted. It's a weird behavior.. I read that a div is illegal inside a paragraph, but it doesnt work with span either.
Does anyone have any pointers? Any help is greatly appreciated.
The problem of the text getting inserted after the img can be fixed by putting an as the link text i.e. instead of <a id='<?php echo $new_file; ?>' class='videoplaceholder'></a> you can use <a id='<?php echo $new_file; ?>' class='videoplaceholder'> </a>. I am not sure about the class though, may be there is a way to prevent TinyMCE from adding the class by default.

Categories

Resources