hyperlink should not be clickable if its already opened in new window - php

I have a hyper-link in my php page which opens in new window when it is clicked. But I want it should open only in one window at time, it should ne open if it is already open in new window of browser. Suppose If I click 5 times it is opening in 5 new windows, I want it only in one window. This problem is coming with Mozilla Firefox Please help me doing this with JavaScript or Jquery.
Thanks
thanks. and sorry to share incomplete information. Actually multiple links will be created through php code, which will be opened in different windows. I have used JavaScript to open them in different window. My problem is that same url should not open again if it is already open in window or if any url is clicked multiple times it should open only one window.
Here is my code :
PHP Code
<?php
$Class="class='links'";
$jsfun = 'javascript:openMyLink';
while(condition)
{
print "Click Here";
}
?>
JS code :
function openMyLink(arg1,arg2,arg3) {
var url = "http:///launcher.php?arg1="+arg1+"&arg2="+arg2+"&arg3="+arg3;
newwindow = window.open(url, "Mywindow",'height=596, width=795, left=0, top=0, resizable=yes, scrollbars=no, toolbar=no, menubar=no');
}
I tried to change the second parameter of window.open as dynamic also instead of "Mywindow" but it did not work too. Its not giving the issue with chrome or IE.

If you want to open a site in new window only once you clicked on it, use below code...
<a id="target" href="javascript:void(0)" onClick="myfunc()">click here</a>
<script type="text/javascript">
x=0;
function myfunc()
{
if(x==0)
{
x+=1;
window.open("<--- YOUR SITE URL --->");
}
}
</script>

On your first page have this code,
jQuery(document).ready(function($){
$("#theLink").click(function(e){
if($(this).attr("at")=='1')
{
e.preventDefault();
return false;
}
});
});
and your link should be having an attribute 'at' set to '0' just
like
<a id="theLink" href="demo.html" target="_blank" at="0">Click here to go away</a>
and let your children or newly opened page have this code.
window.opener.$("#theLink").attr("at","1");
$(window).unload(function() {
window.opener.$("#theLink").attr("at","0");
});
This is little tricky but works.
Worked great for me on IE8.

Related

How to prevent reloading of a page after clicking on a hyperlink but redirect to that page and work out the necessary code written over there?

My question may sound confusing but actually it's not. Let me clear you the things. The scenario is I've following HTML code:
/*This is the hyperlink I've given for example here. Many such hyperlinks may present on a webpage representing different question ids' */
<a delhref="http://localhost/eprime/entprm/web/control/modules/questions/manage_question_issue.php?op=fixed&question_id=21679" title="Fixed" href="#fixedPopContent" class="fixed" data-q_id="21679" id="fix_21679">Fixed</a>
/*Following is the HTML code for jQuery Colorbox pop-up. This code has kept hidden initially.*/
<div class="hidden">
<div id="fixedPopContent" class="c-popup">
<h2 class="c-popup-header">Question Issue Fix</h2>
<div class="c-content">
<h3>Is question reported issue fixed?</h3>
Yes
No
</div>
</div>
</div>
Now upon clicking on this hyperlink I'm showing a pop-up(I've used jQUery Colorbox pop-up here. It's ok even if you are not familiar with this library.) On this pop-up there are two buttons Yes and No. Actually these are not buttons, these are hyperlinks but showing as a buttons using CSS. Now my issue is when user clicks on hyperlink 'Yes' the page is redirecting to the href attribute value and the page reloads.
Actually I want to get to the page mentioned in href attribute but the page should not get reload or refresh. How to achieve this? Following is the jQuery code for colorbox pop-up as well as for Yes and No buttons present on this pop-up. I've tried this much but it didn't work for me. The page is getting redirected and reloaded.
My code is as follows:
$(document).ready(function() {
$(".fixed").click(function(e) {
var action_url1 = $(this).attr('delhref');
var qid = $(this).data('q_id');
$('#fixedPop_url').attr('href', action_url1);
$(".fixed").colorbox({inline:true, width:666});
$("#fixedPop_url").click(function(event) {
event.preventDefault();
$("#fix_"+qid).hide();
$("#notfix_"+qid).show();
});
$(".c-btn").bind('click', function(){
$.colorbox.close();
});
});
});
So you need to load the page at the url but not navigate to it.
You can use .load() .
So in your case, lets say that your pop container div class is .popup, and the div where you want to load the urls content has an id say #container.
$(".popup a").on('click', function(e){
e.preventDefault();
var url = $(this).attr('delhref');
$("#container").load(url);
});
Few things to keep in mind,
This will mostly not work for urls pointing to any other domain. (Same Origin Policy)
Any content loaded with this function (.load()) shall be inserted within the container and all the incomming scripts if any shall be executed.
You can do that with history.js. Here is an example;
HTML:
Delete
Update
<div id="content"></div>
JS:
var History = window.History;
if (!History.enabled) {
return false;
}
History.Adapter.bind(window, 'statechange', function() {
var State = History.getState();
$('#content').load(State.url);
});
$('body').on('click', 'a', function(e) {
var urlPath = $(this).attr('href');
var Title = $(this).text();
History.pushState(null, Title, urlPath);
return false;
});
You can see code here: jsfiddle code
You can see demo here: jsfiddle demo
Note: Urls in example cannot be found. You need to update it according to your needs. This simply, loads content in href without refreshing your page.

HTML link error to PHP pages

I have a few buttons that are properly linked on my website, it rarely works, most of the time it does not. when I right click and open in a new window they work else it wont.
http://studentnet.kingston.ac.uk/k1003140/group8
Any one knows why and how?
here how they are linked:
Spain
and the page spain exists. please do not give me a minus if you won't even comment.
I checked your website and i found you have a js script called general.js it calls this function
$(document).ready(function() {
//initial
$('#midcontent').load('content/index.php');
//handle menu clicks
$('ul li a').click(function() {
var page = $ (this).attr('href');
$('#midcontent').load('content/' + page + '.php');
return false;
});
});
and content/index.php is unreachable and causes an error in the console log, when i disabled javascript on your webpage the links worked fine.
as you see it adds extra content/ before the link and .php at the end, try to remove it

Open URL in the New Tab : WordPress

When I uploads a image into the page using Add Media, I am setting url for that image, so that when user clicks on that image he should get redirect to another page. problem is, is get loading on same page.
I want it should get load in to another tab. I can't edit each href with target="_blank" as i have lots of images.
I just want to know is there any particular php file that should I edit or any other way is there.
Please help me to solve this problem
<script>
$(function(){ $("a img").attr("target","_blank"); });
</script>
Add this in <head>.
It's easy to set target="_blank" for images:
Click an image to activate its settings pop-up window.
Click the Advanced Settings tab.
Scroll down to "Target" and you'll see the "open in a new window" checkbox there.
For old images, you'll have to make the change manually.
Hope this helps!
You could use JavaScript window.open(), like:
function imgWin(win, winName, imgArray){
var dot, hsh;
for(var i=0,l=imgArray.length; i<l; i++){
(function(i){
dot = imgArray[i].lastIndexOf('.');
hsh = imgArray[i].slice(0, dot);
imgArray[i].onclick = function(){
open(win+'#'+hsh, winName, 'resizable=1');
}
})(i);
}
}
Then you could even get your images easily, like:
var imgs = document.getElementsByTagName('img');
imgWin('imgwin.php', 'My Images, imgs);
Note, that window is implicit, so you dont actually need to writewindow.open().open()` will work fine, in this case.

Js on click Open link, then copy text, then display an alert

I'm trying to develop a custom coupon system, and all works with IE, but when I try to use the following code on firefox or safari on click it open link and display alert but doesn't copy text:
<script type="text/javascript">
function copy_to_clipboard(text)
{
if(window.clipboardData)
{
window.clipboardData.setData('text',text);
}
else
{
}
alert('<?php echo get_option('custom_message'); ?> Powered by: WpCode.net Couponica');
return false;
}
</script>
And on the link:
<a onclick="copy_to_clipboard('code to copy')" href="link to open" style="margin-left:40px;" target="_blank">
What's wrong? How can I change this to make it work on firefox?
Clipboard access is not available in Firefox. Take a look at http://code.google.com/p/zeroclipboard/ for a Flash based alternative.
It is not possible to copy to clipboard in other browser then IE due security issues. You can use Flash for it, but from Flash 10.0 the security has increased aswell, so only users with Flash 9 or lower are able to copy.
What you can do is when you want someone to copy something, show a popup with a textbox with only the text the need to copy.
function copyLink(){
var link = window.location.href;
navigator.clipboard.writeText(link);
alert('link copy to clipboard');
}
<button class="btn btn-primary" onclick="copyLink()" >Share</button>

How to make a url from a popup window to be displayed on the parent window?

I have two pages, let's call them pageA.php and pageB.php.
Page A contains a textarea and a link. I want the link to open to pageB.php (a popup window). On pageB.php, there's a url that, when I click on it, the url will be displayed inside the textarea of pageA.php and pageB.php (the popup window) will close itself once I click on the url.
The link in the popup would be something like
Click Me in Popup Window
and the code would be (not tested and no error handling)
<script language="javascript">
function ProcessLinkClick(oThis) {
if (window.parent) {
var textBox = window.parent.document.getElementById("IdOfTextBoxInParentWindow");
textBox.value = oThis.href;
}
window.close();
}
</script>

Categories