Jump to content

Having troubles creating a link


_SAi_

Recommended Posts

Hello,

I have a bit of html I would like to link to instead of having my page load it:

[code]
<div id="plugin" onmousedown="HSVslide('drag','plugin',event)" style="TOP: 240px; LEFT: 430px; Z-INDEX: 20;">
<div id="plugHEX" onmousedown="stop=0; setTimeout('stop=1',100);">F1FFCC</div>
<div id="plugCLOSE">Background Colour</div><br>
<div id="SV" onmousedown="HSVslide('SVslide','plugin',event)" title="Saturation + Value">
<div id="SVslide" style="TOP: -4px; LEFT: -4px;"><br /></div>
</div>

<form id="H" onmousedown="HSVslide('Hslide','plugin',event)" title="Hue">
  <div id="Hslide" style="TOP: -7px; LEFT: -8px;"><br /></div>
  <div id="Hmodel"></div>
</form>
</div>

[/code]

I would like to link to it so I tried this without anything happening.

In my <head> section I created a function:

[code]
<script type="text/javascript">
function callBGhex()
{
document.write('<div id="plugin" onmousedown="HSVslide('drag','plugin',event)" style="TOP: 140px; LEFT: 430px; Z-INDEX: 20;">');
document.write('<div id="plugHEX" onmousedown="stop=0; setTimeout('stop=1',100);">F1FFCC</div><div id="plugCLOSE" onmousedown="toggle('plugin')">X</div><br>');
document.write('<div id="SV" onmousedown="HSVslide('SVslide','plugin',event)" title="Saturation + Value">');
document.write('<div id="SVslide" style="TOP: -4px; LEFT: -4px;"><br /></div>');
document.write('</div>');
document.write('<form id="H" onmousedown="HSVslide('Hslide','plugin',event)" title="Hue">');
document.write('<div id="Hslide" style="TOP: -7px; LEFT: -8px;"><br /></div>');
document.write('<div id="Hmodel"></div>');
document.write('</form>');
document.write('</div>');
}
</script>

[/code]

And then for my link in the <body> section I used:

[code]
<a href="javascript:onMouseUp=callBGhex();">Show IT!!</a>
[/code]

Am I forgetting something or is something wrong?

Thank you!
Link to comment
https://forums.phpfreaks.com/topic/33070-having-troubles-creating-a-link/
Share on other sites

Formatting HTML output is always anoying.. this should work (tested in IE7) tho, but there's an error somewhere when it's done displaying ::). I can't find it. Need a new pair of eyes!

[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Test</title>
   
    <script language="javascript" type="text/javascript">
    <!--
        function writeHTML()
        {
            var html = '';
            html += '<div id="plugin" onmousedown="HSVslide(\'drag\',\'plugin\',event)" style="TOP: 240px; LEFT: 430px; Z-INDEX: 20;">';
            html += ' <div id="plugHEX" onmousedown="stop=0; setTimeout(\'stop=1\',100);">F1FFCC<\/div>';
            html += ' <div id="plugCLOSE">Background Colour<\/div><br>';
            html += ' <div id="SV" onmousedown="HSVslide(\'SVslide\',\'plugin\',event)" title="Saturation + Value">';
            html += ' <div id="SVslide" style="TOP: -4px; LEFT: -4px;"><br \/><\/div>';
            html += ' <\/div>';
            html += ' ';
            html += ' <form id="H" onmousedown="HSVslide(\'Hslide\',\'plugin\',event)" title="Hue">';
            html += '  <div id="Hslide" style="TOP: -7px; LEFT: -8px;"><br \/><\/div>';
            html += '  <div id="Hmodel"><\/div>';
            html += ' <\/form>';
            html += '<\/div>';
   
            // Write it out
            document.write(html);
        }

        //-->
    </script>
  </head>
  <body>
    <p><a href="javascript:writeHTML();">Click</a></p>
  </body>
</html>
[/code]
[quote author=_SAi_ link=topic=121223.msg498220#msg498220 date=1168105698]
Thanks,

But this appears to load a new page.  I was hoping to add it to the existing page.  Is there a way to do that?
[/quote]

Hmm, you should just be able to use innerHTML on a div for example. Something like (I have not tested)

[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Test</title>
   
    <script language="javascript" type="text/javascript">
    <!--
        function writeHTML()
        {
            var html = '';
            html += '<div id="plugin" onmousedown="HSVslide(\'drag\',\'plugin\',event)" style="TOP: 240px; LEFT: 430px; Z-INDEX: 20;">';
            html += ' <div id="plugHEX" onmousedown="stop=0; setTimeout(\'stop=1\',100);">F1FFCC<\/div>';
            html += ' <div id="plugCLOSE">Background Colour<\/div><br>';
            html += ' <div id="SV" onmousedown="HSVslide(\'SVslide\',\'plugin\',event)" title="Saturation + Value">';
            html += ' <div id="SVslide" style="TOP: -4px; LEFT: -4px;"><br \/><\/div>';
            html += ' <\/div>';
            html += ' ';
            html += ' <form id="H" onmousedown="HSVslide(\'Hslide\',\'plugin\',event)" title="Hue">';
            html += '  <div id="Hslide" style="TOP: -7px; LEFT: -8px;"><br \/><\/div>';
            html += '  <div id="Hmodel"><\/div>';
            html += ' <\/form>';
            html += '<\/div>';
   
            var divToShowHtml = document.getElementById("htmlhereplease");
            if (divToShowHtml)
            {
                // Write it out
                divToShowHtml.innerHTML = html;
            }
            else
            {
               // couldn't find div.. ?
             }
        }

        //-->
    </script>
  </head>
  <body>
    <p><a href="javascript:writeHTML();">Click</a></p>
    <div id="htmlhereplease">
        Magic happens!
    </div>
  </body>
</html>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.