简体   繁体   中英

How can I add in anchor tags to html where links are set with javascript?

I have an old page where all the links on the page are set with javascript and no anchor tags are used on the site.

I need to rebuild these pages but need the anchor text to be added to the html. Currently spans with IDs are used to tell the javascript where to create the links. For example:

<span id="sleeponit_hypertext" style="cursor:pointer"><font face="Arial"><span 
    style=" font-size:15px"><b><u>National Aeronautics 
    and Space Administration</u></b></span> 

Would be used by the javascript to set National Aeronautics and Space Administration as a link (using findobject and actionevents to set the location of where onclick should take the user).

Is there anyway I can automatically have the anchor tags? Any ideas on how to approach the problem would be helpful.

EDIT: To help clarify, the javascript functions that sets the link are as follows:

    FindObject( "sleeponit_hypertext").onmousedown = function(){ sleeponit_hypertext_MouseDown();  };
FindObject( "sleeponit_hypertext").onmouseup = function(){ sleeponit_hypertext_MouseUp(); };
 FindObject( "sleeponit_hypertext").onmousemove = function(){ sleeponit_hypertext_MoveIn(); };
 FindObject( "sleeponit_hypertext").onmouseout = function(){ sleeponit_hypertext_MoveOut();  };
 actions.sleeponit_action43 = new SetCursorAction( "pointer");
 actions.sleeponit_action44 = new SetCursorAction( "default");
 actions.sleeponit_action55 = new PageAction( "indivlearning.html")

PageAction function just loads the window with the filename passed through (in this case indivlearning.html).

parent.loadPage(this.m_PageName)

Where this.m_PageName is what was passed to PageAction.

I'd love to fire the PageActions with the corresponding links on page load with the added anchor tags.

(Edited)

OK, I understand better now.

I would probably write some jQuery code that iterates through the span[@id] elements; have it programatically fire the click event on each one; but modify the js routine that says newURL = ....; window.location = newURL; newURL = ....; window.location = newURL; such that instead of changing window.location , it changes the DOM tree under that span, replacing the inner span with

<a href="newURL">[text content of the <b><u>]</a>

Once the DOM tree is transformed, you can have it spit out the resulting HTML.

The above description is sketchy... I didn't want to elaborate unnecessarily. If you have questions, fire away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM