Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to globally disable onclick

Status
Not open for further replies.

karnesb

Technical User
Oct 12, 2008
6
US


I want to write a JavaScript that either ignores all onclick link references found in the text of the page file, or does a search and replace whereby the following string is found and replaced with nothing.

onclick="popupEvent


BACKGROUND:
I'm using a third-party calendar program. The program is designed to produce both a mouseover, "title" window, and an onclick, pop up window tied to dates where events are scheduled. The calendar view I'm using produces a mini, month-at-a-glance view.

My web site has both a member (private) and public section. I want the onclick feature active in the member section, but don't want it to work in the public section . The public calendar is used to show non-members what great events they are missing by not being members, and is there to generate sales. All I want for the public calendar is the "title" window. Anything more would give away the farm, so to speak.

SET UP:
To insert one of the calendar's 4 views into any web page, you place the same two lines of code in the php file; one in the header, and one just below the <body> tag. Those set up the basic calls to display any calendar "views" you want to display. Then within the body of the page, you inset a line of code to call the calendar you wish, where you want it to show up. It is that simple.

The source code that makes up the final, displayed calendar page is a combination of the original code, and that code inserted from multiple php files from which it was called. That "called" code includes the onclick link references. What I want to do is insert a master or global java script into the "parent" pages, that ignores any and all onclick commands that may have been inserted there, or replaces them with nothing - effectively disabling them.

I am using two separate files (web pages) to display this calendar; one in the public section and one in the private section. The challenge is that the calendar software isn't set up to allow the popup to be turned off and on at the file (page) level, just globally for "all" pages. If it did I could have the global feature "on" and turn off the pop up on the public page just by adding a line of code. But, alas, no luck. Please note... the calendar's documentation / support forum does provide some on/off code strings, just not for this pop up.

To make one of my calendars private, I've copied that file (with calendar code inserted as indicated above) into a secure folder on my server. The other page lives in a separate, non-secure (public) directory. Both pages call the same calendar, but are different web page files stored in different directories.

I spent two days hacking and testing the calendar's php-based, program files to try to circumvent this process, but just no luck. Primary reason is that a few of the pages are scrambled so they can't be hacked, therefore I cannot modify them.

That leaves me with trying to disable the onclick references in the my public file, and here I am.

Suggestions?

Thanks in advance.
Barbara
 
If, as you say the calendar popup can be turned off for all pages, not individual pages, then why not simply turn it off for all pages if the user isn't a logged-in member?

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I must not have been clear. Let me give this another try. The calendar exists once. It can be called to appear in as many web pages as you like. Basically, all you have to do is insert this code where you want it to appear.

<?php require("calendar.php"); ?>

So, when you turn off a feature, you are turning it off for the calendar, univerally. Then, every web page that contains the above code is effected.

I have the above code inserted into two web pages. One is located in a protected, member folder - meaning only a member with the right passwords can open the "folder" that contains a file which includes the above calendar code. It is the FOLDER not the CALENDAR that is being secured. The other file that contains the above code is located in a public folder, so it can be seen by anyone.

One calendar, two web files containing the same code.

Any ideas??
 
It might have been me who wasn't clear enough...

When a user is logged in, don't cripple anything. When a user is not logged in, turn off the popup option - globally.

Users who are members but who have not logged in will see the crippled version, but when they log in, they will see the full version.

Non-members who are not logged in will also see the crippled version.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 

What you suggest is exactly what I'm trying to do. When a user is logged in in they see everything. When they are not logged in they don't; neither do non-members.

But, with one calendar being pointed to from two web pages, and that one calendar being controlled by a single admin center, I can either turn off the pop ups or turn them on in that admin center for the one calendar - no matter how many pages point to it.

So, I'm left trying to turn off the pop ups on the public web page by inserting a JavaScript that either:

1. turns off / ignores the onclick commands, or
2. does a search and replace for the onclick string and replaces it with nothing.

Still hoping for suggestions.

Best,
B
 
and that one calendar being controlled by a single admin center

That would be the cause of my suggestion not working for you... I had no idea you turned the calendar off via an admin centre. I had assumed that when you said you could turn it off for all pages that you meant programatically (e.g. as some sort of param passed to a constructor).

I'd go with option 1 from your previous post, but would have no idea what the code would be given we don't know which calendar you are using or the code you're using to implement it. Perhaps you could post a URL?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
>What I want to do is insert a master or global java script into the "parent" pages, that ignores any and all onclick commands that may have been inserted there, or replaces them with nothing - effectively disabling them.
What is "parent" page(s)? By what mechanism the parent-child relationship is established? Explain it a bit and I'll get there by then.
 
Below is the uri for a copy of the calendar I put online. If you right click and download this php file, and open it in a text editor (WordPad leave the structure in place), then click on the same link to open it in a web browsers, right click to view the source, and compare the two text versions of the file, you can see the before and after views of the code.


Let me know your thoughts, and thanks.
B
 
I don't think I get the meaning of download... thing (it won't do by "download" to inspect the server-side script, I think). Besides, I don't see "calendar" on the url...

No matter, in all the uncertainties, I would suggest the simplest client-side script to disabling all the onclick event handling on the "child"(?).
[tt]
//ochildwin is the reference handler of the "child" window
var ctag=ochildwin.document.getElementsByTagName("*");
for (var i=0;i<ctag.length;i++) {
ctag.onclick=function() {return false;};
}
[/tt]
In the "parent" use a function to do that job immediately after the calling up of the "child". Since, no all browser support a simpler document.readyState, I would say, to simplify thing, use a setTimeout() repeatedly calling the same function for a reasonably prolonged period of time before considered safely done.
 
Gotcha. So... would the setTimeout() string for this projecct look something like this, or did I insert the wrong variable?


var ctag=ochildwin.document.getElementsByTagName("*");
for (var i=0;i<ctag.length;i++) {
ctag.onclick=function() {return false;};

setTimeout("onclick()", 1000);

}
 
Also, tried a few versions of the script above. Not working, but I'm absolutely confident we're on the right track. Being that JS is not my primary coding expertise, I know I'm not writing and/or inserting it correctly, so below is the code for both the parent page (as I'm calling it) that lives on the server, and the source code for that page as it appears when the uri is opened online. Note, if there were more event dates, or the event info changed the hyperlink references in the "open" page would change.

To reiterate... I want to KEEP the "title=" references in the final, open version, I just don't want them to be clickable. Can't achieve this in the original php files, as the source for those pages is scrambled by the programmer.

Think you can help?


----------------------------------------------------
BELOW: Parent Source Code
----------------------------------------------------


<html>

<head>

<title>KC Mini Calendar View</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

<?php $CSS=1; require("calendar.php");


?>

<style type="text/css">

<!--

.style1 {

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 9px;

}

-->

</style>




</head>

<body>

<?php $OL=1; require("calendar.php"); ?>





<div align="center">


<table width="100%" align="center">

<tr><td align="center">



<?php




$overLIB="0";


require("calendar.php");


?>




</td>

</tr></table>

</body>

</html>

----------------------------------------------------
BELOW: Source code from opened uri ----------------------------------------------------

<html>

<head>

<title>KC Mini Calendar View</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

<link href="/calendar/theme/kc/esstyle.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
<!--
.s24 {background-color: #FBF484;}
.s23 {background-color: #CCFF00;}
.s21 {background-color: #F2BFBF;}
.s22 {background-color: #A4CAE6;}
.s29999 {background-color: #FFC18A;}
-->
</style>

<style type="text/css">

<!--

.style1 {

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 9px;

}

-->

</style>




</head>

<body>

<script type="text/JavaScript">
var ol_width=200;
var ol_delay=100;
var ol_fgcolor="#FFFFFF";
var ol_bgcolor="#C0925F";
var ol_offsetx=12;
var ol_offsety=16;
var ol_border=1;
var ol_sticky=1;
var ol_vauto=1;
</script>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div><script type="text/JavaScript" src="/calendar/overLIB/overlib_mini.js"><!-- overLIB (c) Erik Bosrup --></script>




<div align="center">


<table width="100%" align="center">

<tr><td align="center">



<script type="text/JavaScript">
<!--
function popupEvent(ev, w, h) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
win = window.open("/calendar/functions/popup.php?ev=" + ev + "&readFile=0&readSQL=1&showCat=&oc=1","Calendar","scrollbars=yes,status=no,location=no,toolbar=no,menubar=no,directories=no,resizable=yes,width=" + w + ",height=" + h + ",top=" + wint + ",left=" + winl + "");
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
//-->
</script>
<table class="mainTable" cellspacing="1" cellpadding="0">
<tr>
<td class="monthYearText monthYearRow" colspan="7">
October 2008
</td>
</tr>
<tr class="dayNamesText">
<td class="dayNamesRow" width="14%">S</td>
<td class="dayNamesRow" width="14%">M</td>
<td class="dayNamesRow" width="14%">T</td>
<td class="dayNamesRow" width="14%">W</td>
<td class="dayNamesRow" width="14%">T</td>
<td class="dayNamesRow" width="14%">F</td>
<td class="dayNamesRow" width="14%">S</td>
</tr>
<tr class="rows">
<td class="s20">&nbsp;</td>
<td class="s20">&nbsp;</td>
<td class="s20">&nbsp;</td>
<td class="s2">1</td>
<td class="s2">2</td>
<td class="s2">3</td>
<td class="s200">4</td>
</tr>
<tr class="rows">
<td class="s200">5</td>
<td class="s2">6</td>
<td class="s2">7</td>
<td class="s2">8</td>
<td class="s24" title="Court Research " onclick="popupEvent(2454749,550,420)" style="cursor: pointer;">9</td>
<td class="s23" title="Sub 2 Webinar " onclick="popupEvent(2454750,550,420)" style="cursor: pointer;">10</td>
<td class="s200">11</td>
</tr>
<tr class="rows">
<td class="s200">12</td>
<td class="s2">13</td>
<td class="s2">14</td>
<td class="s2">15</td>
<td class="s2">16</td>
<td class="s2 today">17</td>
<td class="s200">18</td>
</tr>
<tr class="rows">
<td class="s200">19</td>
<td class="s2">20</td>
<td class="s2">21</td>
<td class="s2">22</td>
<td class="s2">23</td>
<td class="s2">24</td>
<td class="s200">25</td>
</tr>
<tr class="rows">
<td class="s200">26</td>
<td class="s2">27</td>
<td class="s2">28</td>
<td class="s2">29</td>
<td class="s2">30</td>
<td class="s2">31</td>
<td class="s20">&nbsp;</td>
</tr>
</table>
<table class="navTable" cellspacing="0" cellpadding="0">
<tr>
<td align="left" width="33%"><a href="mini-view-public.php?mo=9&amp;yr=2008" class="navTableText"><<</a></td>
<td align="center" width="34%"><a href="mini-view-public.php?mo=10&amp;yr=2008" class="navTableText">-=-</a></td>
<td align="right" width="33%"><a href="mini-view-public.php?mo=11&amp;yr=2008" class="navTableText">>></a></td>
</tr>
</table>




</td>

</tr></table>

</body>

</html>
 
I meant something like this: set up a function, say disableclick() in the parent page:
[tt]
var owin;
var ncount=0;
var nmax=10; //10*50 ms to continuously to try disabling
function disableclick() {
if (owin && !owin.closed && owin.document && ncount<=nmax) {
var ctag=owin.document.getElementsByTagName("*");
for (var i=0; i<ctag.length; i++) {
ctag.onclick=function() {return false;};
}
ncount++;
setTimeout("disableclick()",50); //mostly redundantly : just for cross-browser applicability and assurance to get done
} else {
ncount=0; //reset
}
}
[/tt]
and when you open the child somewhere in the parent call it immediately after .open().
[tt]
function somehandler() { //figuratively only
//etc etc some operations
ochildwin=window.open("surl_calendar.php"); //figuratively
disableclick();
//etc etc other operations
}
[/tt]
The redundancy of continuously trying to disabling click handler is due to the cross-browser rendering of something equivalent to document.readyState=="complete" would be very clumsy and hard to comprehend. Hence, an easier path is to do it continuously for an adhoc period of time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top