dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: run java from txt link

  1. #1
    Join Date
    Jul 2011
    Posts
    1

    Red face run java from txt link

    Hi and thanks in advance.

    I am running the code below linked in from an external .js linked in this way: <script type="text/javascript" src="bookmark.js"></script>.


    And the code is:

    function bookmark(url,title){
    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(url,title);
    } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
    } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
    }
    }

    I would like to run the script with an onclick event of text that reads Bookmark Us!!!

    Can someone please help me to do this?

    I got it too work with an input value"Bookmark Us!!!" but that puts it in a txt field and it doesn't look right. My website has a black background with pink text and I would rather not muddle the code with a bunch of syntex defining the text field so it would blend better. If there is a simpler, neater way I would love for someone to demonstrate it.

    I tried the span tag but couldn't get the java to work with it.

    I am super new at HTML in general, and I have always had trouble with Javascript. Thanks again!

  2. #2
    Join Date
    May 2011
    Posts
    194

    input button or DIV or H1 or SPAN ....

    Hi,

    <HTML>
    <HEAD>
    <SCRIPT>

    function bookmarkInputButton(url,title, ptOfInoutButton, stMessage)
    // ptOfInoutButton pointer of object with property .value f.e. input button
    {
    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
    {window.external.AddFavorite(url,title);}
    else
    {
    if (navigator.appName == "Netscape")
    {window.sidebar.addPanel(title,url,"");}
    else
    {
    // alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
    ptOfInoutButton.value=stMessage;
    }
    }
    }

    function bookmarkSPANorDIVOrH1(url,title, ptSpanOrDIVorH1, stMessageWithHTMLtag)
    // ptSpanOrDIVorH1 pointer of object with property .innerHTML or .innerText f.e. DIV
    {
    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
    {window.external.AddFavorite(url,title);}
    else
    {
    if (navigator.appName == "Netscape")
    {window.sidebar.addPanel(title,url,"");}
    else
    {
    // alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");

    ptSpanOrDIVorH1.innerHTML=stMessageWithHTMLtag; // you can use html tag like <B> andd plain text

    // ptSpanOrDIVorH1.innerText=stMessage; // you can use NO html tag like <B>, only plain text

    // ptSpanOrDIVorH1.style.visibility="hidden"; // only if you want: make Span or DIV oder H1 invisible.
    // browser renders .innerHTML or .innerText invisible

    // ="visible"
    // browser renders .innerHTML or .innerText visible (default)
    }
    }
    }

    </SCRIPT>
    <BODY>

    <INPUT TYPE="TEXT" ID="ID_InputButton" VALUE="This text will be changed" onclick="bookmark('http://www.test.com','Testpage',this,'Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark');")>

    <DIV ID="ID_DIV" onclick="onclick="bookmarkSPANorDIVOrH1('http://www.test.com','Testpage',this,'You have <B>bookmarked</B> !');">
    Please click this text to bookmark ! (This text will be changed.)
    </DIV>


    <DIV ID="SPAN_DIV" onclick="onclick="bookmarkSPANorDIVOrH1('http://www.test.com','Testpage',this,'You have <FONT COLOR="red"><B>bookmarked</B></FONT> !');">
    Please click this text to bookmark ! (This text will be changed.)
    </SPAN>

    <H1 ID="ID_H1" onclick="onclick="bookmarkSPANorDIVOrH1('http://www.test.com','Testpage',this,'You have <B>bookmarked</B> !');">
    Please click this text to bookmark ! (This text will be changed.)
    </H1>

    <!-- and so on: all objects with porperty .innerHTML or .innerText -->



    </BODY>
    </HTML>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles