hyperlink - createElement("a") - FireFox JavaScript -
hyperlink - createElement("a") - FireFox JavaScript -
i have problem. have iframe(editable) , when click button create link. that's not problem. but, after remain in "link" mode. have problem in firefox. what's wrong. thx lot.
javascript function in index.php
function insertlink(verlinkung,text) { var doc = document.getelementbyid("frame").contentwindow.document; var sel = doc.getselection(); if (sel.rangecount > 0) { var range= sel.getrangeat(0); myparent=document.getelementbyid("frame").contentwindow.document.body; alink=document.createelement("a"); text= document.createtextnode(text); alink.href = verlinkung; if (document.getelementbyid('check_underline').checked == false) { alink.setattribute("style","text-decoration: none;"); } else { alink.setattribute("style","text-decoration: underline;"); } alink.appendchild(text); myparent.appendchild(alink); range.insertnode(alink); } }
-- in same site javascript function
<img src ='./images/toolbar/plus.png' onmousedown = "insertlink(document.getelementbyid('link_href').value,document.getelementbyid('link_text').value);">
in index.php
<iframe src = './editor.php' id = 'frame' class = 'iframe_design'>
content of iframe in editor.php:
<!doctype html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script language = 'javascript'> function lade() { document.body.contenteditable='true'; document.designmode='on'; void 0; } </head> <body style = 'font-family: verdana; font-size: small;'> </body> </html>
so, , when create link image click, remain in "hyperlink" mode. in firefox. can write normal text, works hyperlink.
what you're doing should work.
try simplified version:
<div id="x">a link should appear here: </div> <script> var = document.createelement("a"); var text = document.createtextnode("i'm link"); a.setattribute("style", "text-decoration: underline;"); a.setattribute("href", "https://github.com/adrianblynch?tab=repositories"); a.appendchild(text); document.getelementbyid("x").appendchild(a); </script>
works me in chrome , firefox.
javascript hyperlink createelement
Comments
Post a Comment