Replace a hyperlink with an iframe

I am trying to replace internal links:

<div class="activityinstance">
    <a href="">activity</a>

to become:

    <div class="activityinstance">
        <iframe src="">

I have been able to replace just the text with an iframe using jquery.

But this is proving to be quite hard.

Another difficulty is that it needs to only be links with hvp in the address.

I appreciate any help - thanks.

Answers 1

  • A sample of:

    <div class="activityinstance">
        <a href="">activity</a>

    [Because of a fact that having HTML inside of an IFRAME tags has no bearing, and is a complete waste of bytes, we will leave it out. And because this solution doesn't need wrappers, we'll stick to the good old (plain and clean) JavaScript].

    The snippet:

            function( a ) {
            if( a.href.match(/hvp/) ) {
                a.outerHTML = "<iframe src=" + a.href + "><\/iframe>" 
        } );

    will result in clean HTML such as:

    <div class="activityinstance">
        <iframe src=""></iframe>

    ...of course, without indentations and unnecessary white-spaces.

Related Articles