Pages

Friday, November 18, 2011

Email Cursor


This script causes an "email me" message to follow your mouse cursor around the page. When clicked the default email client will open so an email can be sent.
Change the message, email addy and font type at the top of the email cursor script. Compatible with normal stylesheet rules for link colors, etc
Very useful and easy to install. :)
Installation:
Copy the code below and paste this into your html document as the last thing on the pagejust above the closing body tag. </body>

<script language="JavaScript"> 
<!-- E-mail Stalker Script by kurt.grigg@virgin.net --> <!-- Get script 
at http://www.hypergurl.com // Change to suit here!------------------ msg="Click 
here to e-mail"; mail="mailto:support@hypergurl.com"; fnt='Verdana'; 
fsze='2'; speed=3; //---------------------------------- Y=0,X=0,my=0,mx=0,angle=0,dy=0,dx=0,tmr=null; 
ns=(document.layers)?1:0; off=(document.layers)?'hide':'hidden'; on=(document.layers)?'show':'visible'; 
if (ns) document.write('<layer name=n top=0 left=0><font face='+fnt+' 
size='+fsze+'><a href='+mail+'>'+msg+'</a></font></layer>'); 
else{ document.write('<div id="c" style="position:absolute"><div 
style="position:relative">'); document.write('<div id="i" 
style="position:absolute;width:200px;height:30px"><font face='+fnt+' 
size='+fsze+'><a href='+mail+'>'+msg+'</a></font></div>'); 
document.write('</div></div>'); } if (ns){ window.captureEvents(Event.MOUSEMOVE); 
function nMouse(evnt){ my=evnt.pageY+20;mx=evnt.pageX } } else{ function iMouse(){ 
my=event.y+20;mx=event.x; } } function stalk(){ if (ns) window.onMouseMove=nMouse; 
else {document.onmousemove=iMouse;c.style.top=document.body.scrollTop} var layer=(document.layers)?document.n:i.style; 
Y=my-dy;X=mx-dx; angle=Math.round(Math.atan2(Y,X)*180/Math.PI); if (angle < 
0) angle += 360; y = Math.round(speed*Math.sin(angle*Math.PI/180));x = Math.round(speed*Math.cos(angle*Math.PI/180)); 
dy+=y;dx+=x; if ((dy > my-speed*2) && (dx > mx-speed*2) && 
(dy < my+speed*2) && (dx < mx+speed*2)) {clearTimeout(tmr);layer.visibility=off;} 
else{layer.visibility=on;layer.top=dy;layer.left=dx} tmr=setTimeout('stalk()',10); 
} stalk(); //--> </script>

Always On Top Javascript


This floating message javascript is very useful, especially if you want the visitor to see a prominent advertising banner, etc, where the message is always on top of other page content. I'm sure you can think of some very good uses for this script.
The good part of the floating message script is that as you scroll the page, the message scrolls with it, hence the name of "always on top". The message can either flash on and off, as in the example, or be static and you can add all normal html attributes such as links,font type and color, etc.
The floating message javascript is a breeze to set up. Of course your colors might be a little different than the very bright example on this page.
STEP 1
Copy the code below and paste this within the <body> and </body> section of your html document.
Configure the floating message etc, to suit, at the top of the script. All necessary instructions are contained at the top of the script, showing what and where you can change to suit your needs and site design.

<script> //enter your message 
in this part, including any html tags var message='<center><b><font 
color=blue size=4><a href="hosting.html">Webhosting with simply 
super support!<br>Click Here!</a></font></b></center>' 
//enter a color name or hex value to be used as the background color of the message. 
Don't use hash # sign var backgroundcolor="red" //enter 0 for always 
display, 1 for a set period, 2 for random display mode var displaymode=0 //if 
displaymode is set to display for a set period, enter the period below (1000=1 
sec) var displayduration=10000 //enter 0 for non-flashing message, 1 for flashing 
var flashmode=1 //if above is set to flashing, enter the flash-to color below 
var flashtocolor="yellow" ///////////////do not edit below this line//////////////////////////////////////// 
<!-- script distributed by http://www.hypergurl.com function regenerate(){ 
window.location.reload() } var which=0 function regenerate2(){ if (document.layers) 
setTimeout("window.onresize=regenerate",400) } function display2(){ 
if (document.layers){ if (topmsg.visibility=="show") topmsg.visibility="hide" 
else topmsg.visibility="show" } else if (document.all){ if (topmsg.style.visibility=="visible") 
topmsg.style.visibility="hidden" else topmsg.style.visibility="visible" 
setTimeout("display2()",Math.round(Math.random()*10000)+10000) } } function 
flash(){ if (which==0){ if (document.layers) topmsg.bgColor=flashtocolor else 
topmsg.style.backgroundColor=flashtocolor which=1 } else{ if (document.layers) 
topmsg.bgColor=backgroundcolor else topmsg.style.backgroundColor=backgroundcolor 
which=0 } } if (document.all){ document.write('<span id="topmsg" 
style="position:absolute;visibility:hidden">'+message+'</span>') 
} function logoit(){ document.all.topmsg.style.left=document.body.scrollLeft+document.body.clientWidth/2-document.all.topmsg.offsetWidth/2 
document.all.topmsg.style.top=document.body.scrollTop+document.body.clientHeight-document.all.topmsg.offsetHeight-4 
} function logoit2(){ topmsg.left=pageXOffset+window.innerWidth/2-topmsg.document.width/2 
topmsg.top=pageYOffset+window.innerHeight-topmsg.document.height-5 setTimeout("logoit2()",90) 
} function setmessage(){ document.all.topmsg.style.left=document.body.scrollLeft+document.body.clientWidth/2-document.all.topmsg.offsetWidth/2 
document.all.topmsg.style.top=document.body.scrollTop+document.body.clientHeight-document.all.topmsg.offsetHeight-4 
document.all.topmsg.style.backgroundColor=backgroundcolor document.all.topmsg.style.visibility="visible" 
if (displaymode==1) setTimeout("topmsg.style.visibility='hidden'",displayduration) 
else if (displaymode==2) display2() if (flashmode==1) setInterval("flash()",1000) 
window.onscroll=logoit window.onresize=new Function("window.location.reload()") 
} function setmessage2(){ topmsg=new Layer(window.innerWidth) topmsg.bgColor=backgroundcolor 
regenerate2() topmsg.document.write(message) topmsg.document.close() logoit2() 
topmsg.visibility="show" if (displaymode==1) setTimeout("topmsg.visibility='hide'",displayduration) 
else if (displaymode==2) display2() if (flashmode==1) setInterval("flash()",1000) 
} if (document.layers) window.onload=setmessage2 else if (document.all) window.onload=setmessage 
end script --> </script>

Secure your website with JavaScript, NO RIGHT CLICK for Images


Have you ever worked really hard on graphics for your site only to find later that someone has stolen them as their own. You can help encrypt and protect your site with the following HTML codes. No right click block is 100% effective, but they will help against novices.


Use the script below so when someone right clicks to save an image off your page, a message will come up letting people know that your information is copyrighted.


This script may not work in all browsers, and is not foolproof. If someone really wants something from your page they can find ways around it, but at least it's a warning to people who want to take your graphics. But it certainly is a great start.


Copy and paste the following code, and make sure it comes right after your <HEAD> tag:




<script language=JavaScript> var message="Function Disabled!"; function clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if (document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){ alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmousedown=clickIE4; } document.oncontextmenu=new Function("alert(message);return false") </script>




If you don't like using javascript, you can always use a span tag to position a transparent gif over the top of the image like the example code below. Don't forget, you will need to create a transparent.gif to implement this method.
<span style="background-image: url(images/my_image.jpg)"><img src="images/transparent.gif" width="200" height="150" border="0" alt="Protected Image."></span>






"NO RIGHT CLICK" for Source


Here is a handy little script which will not only protect your images from right clicking, but your whole page. Remember this only stops some visitors from viewing your source. There are ways around it and if someone really wants to view your source they may find a way. There is another trick below to protect your source code, so keep reading.




<script language=JavaScript> var message="Function Disabled!"; function clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if (document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){ alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmousedown=clickIE4; } document.oncontextmenu=new Function("alert(message);return false") </script>




Disable Copy and Paste for greater website security.


One of the most popular questions I recieve here at Hypergurl is "How do you stop visitors from stealing your webpage information?"


Below is a little trick that will stop your visitors from copying and pasting your webpage information. Anyone with experience may know a way around this trick. However it will make it hard enough to discourage them and get them moving on to easier targets.


Add the following html code to your BODY tag: 


Here is how your BODY tag may look once implimented: 


<body bgcolor="#FFFFFF" ondragstart="return false" onselectstart="return false">
ondragstart="return false" onselectstart="return false"




Make Your Source Code Vanish.


Now before I show you this last trick to protect your source, I would like you to first view my source. Just click "View" then choose "Source"


How did I do that?


Place your cursor in front of the opening <html> tag and hit your enter button for a while. It will push your source code out of view and this will fool the fools. *smiles*

Add to favorites javascript, bookmark page javascript


This simple piece of javascript code will automatically popup a prompt box to tempt your visitor to bookmark the page into their favorites list.
No programming experience is needed to insert the java code. Simply add the code directly into the <body> tag of your webpage. Works with IE 4+ browser only.

<body onLoad="if(document.all) 
window.external.AddFavorite(window.document.location,window.document.title)">

Wednesday, November 16, 2011

Compare two worksheets using VBA in Microsoft Excel


With the macro below it is possible to compare the content of two worksheets.
The result is displayed in a new workbook listing all cell differences.
 
Sub CompareWorksheets(ws1 As Worksheet, ws2 As Worksheet)
Dim r As Long, c As Integer
Dim lr1 As Long, lr2 As Long, lc1 As Integer, lc2 As Integer
Dim maxR As Long, maxC As Integer, cf1 As String, cf2 As String
Dim rptWB As Workbook, DiffCount As Long
    Application.ScreenUpdating = False
    Application.StatusBar = "Creating the report..."
    Set rptWB = Workbooks.Add
    Application.DisplayAlerts = False
    While Worksheets.Count > 1
        Worksheets(2).Delete
    Wend
    Application.DisplayAlerts = True
    With ws1.UsedRange
        lr1 = .Rows.Count
        lc1 = .Columns.Count
    End With
    With ws2.UsedRange
        lr2 = .Rows.Count
        lc2 = .Columns.Count
    End With
    maxR = lr1
    maxC = lc1
    If maxR < lr2 Then maxR = lr2
    If maxC < lc2 Then maxC = lc2
    DiffCount = 0
    For c = 1 To maxC
        Application.StatusBar = "Comparing cells " & Format(c / maxC, "0 %") & "..."
        For r = 1 To maxR
            cf1 = ""
            cf2 = ""
            On Error Resume Next
            cf1 = ws1.Cells(r, c).FormulaLocal
            cf2 = ws2.Cells(r, c).FormulaLocal
            On Error GoTo 0
            If cf1 <> cf2 Then
                DiffCount = DiffCount + 1
                Cells(r, c).Formula = "'" & cf1 & " <> " & cf2
            End If
        Next r
    Next c
    Application.StatusBar = "Formatting the report..."
    With Range(Cells(1, 1), Cells(maxR, maxC))
        .Interior.ColorIndex = 19
        With .Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        With .Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        With .Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        On Error Resume Next
        With .Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        With .Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        On Error GoTo 0
    End With
    Columns("A:IV").ColumnWidth = 20
    rptWB.Saved = True
    If DiffCount = 0 Then
        rptWB.Close False
    End If
    Set rptWB = Nothing
    Application.StatusBar = False
    Application.ScreenUpdating = True
    MsgBox DiffCount & " cells contain different formulas!", vbInformation, _
        "Compare " & ws1.Name & " with " & ws2.Name
End Sub

This example macro shows how to use the macro above: 

Sub TestCompareWorksheets()
    ' compare two different worksheets in the active workbook
    CompareWorksheets Worksheets("Sheet1"), Worksheets("Sheet2")
    ' compare two different worksheets in two different workbooks
    CompareWorksheets ActiveWorkbook.Worksheets("Sheet1"), _
        Workbooks("WorkBookName.xls").Worksheets("Sheet2")
End Sub


Friday, November 11, 2011

Java Pop-up window from GridView Row Selection


Hi, the following is a complete sample.  I would assume rsSearch is a function defined as <script>  rsSearch(var id) {     }   </script>  
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="ObjectDataSourceCategory"
                    CellPadding="4" ForeColor="#333333" GridLines="None" Font-Size="8pt" Font-Names="Verdana"
                    Width="100%" EmptyDataText="There are no categories defined" PageSize="10">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="btnDetails" runat="server" Text="Details" CausesValidation="false" />
                                <asp:LinkButton ID="btnDelete" runat="server" Text="Delete" CausesValidation="false"
                                    CommandName="Delete" />
                                <asp:Panel ID="pnlPopup" CssClass="catdetpopup" Width="450px" runat="server" Style="display: none;"
                                    Visible="true">
                                    <div style="width: 100%; height: auto; background-repeat: repeat-x; color: Black;
                                        font-family: Calibri" id="dragdiv" runat="server">
                                        <div style="float: right">
                                            <asp:Image runat="server" ID="btnClose" ImageUrl="/globalimages/close_button.gif" />
                                        </div>
                                        <div style="padding: 10px">
                                          <uc1:ucCategoryDetails ID="CategoryDetails1" Cat_id='<%# Eval("CategoryID")%>' runat="server">
                                            </uc1:ucCategoryDetails>
                                        </div>
                                    </div>
                                </asp:Panel>
                                <cc1:ModalPopupExtender ID="mdlpopup1" runat="server" TargetControlID="btnDetails"
                                    PopupControlID="pnlPopup" BackgroundCssClass="popupbackground" DropShadow="true"
                                    Drag="true" PopupDragHandleControlID="dragdiv" CancelControlID="btnClose" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
                            Visible="False" ReadOnly="True" SortExpression="CategoryID" />
                        <asp:BoundField DataField="CategoryName" HeaderText="Category Name" SortExpression="CategoryName" />
                        <asp:CheckBoxField DataField="IsActive" HeaderText="Active" SortExpression="IsActive" />
                    </Columns>
                  
                </asp:GridView>
Css
.catdetpopup
{
    width:500px;
    height:auto;
    border:1px solid black;
    background-color:White;
}
UserControl codebehind
Partial Public Class ucCategoryDetails
    Inherits System.Web.UI.UserControl
    Private _Cat_ID As String
    Public Property Cat_id() As String
        Get
            Return _Cat_ID
        End Get
        Set(ByVal value As String)
            _Cat_ID = value
            Me.odsSubCat.SelectParameters("Cat_ID").DefaultValue = CInt(Cat_id)
          
        End Set
    End Property
End Class
Hope this Helps

------------------------
<script type="text/javascript">
<!-- Begin
function popUp(URL) {day = new Date();
id = day.getTime();
eval(
"page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300,left = 390,top = 362');");
}
// End -->
</script>
Followed by the gridview template.
<ItemTemplate>
<asp:HyperLink ID="idTracking" runat="server" Style="position: relative" Text='<%# Eval("ItemID") %>'NavigateUrl="popUp('../ItemDetail/Default.aspx?ItemID=')"></asp:HyperLink>
</ItemTemplate>
Followed by the VB code behind.
Protected Sub GridView2_RowDataBound(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)Handles GridView2.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hl As HyperLink = DirectCast(e.Row.FindControl("idTracking"), HyperLink) hl.NavigateUrl = "javascript:" + hl.NavigateUrl
End If
End Sub