1

I am trying to create a link that people can put on their own websites that links back to their profile on my site.

I have created the 'widget' using javascript so have a .js file that simplified does this...

document.write("Visit my profile at...");
document.write("    <a href=\"myprofilelink.html\">Click To View</a>");

I want to be able to create a call to it that automatically includes the profile link in the javascript so for example, something like....

<script src="widget.js" id="myprofilelink.html></script>

Can someone point me in the right direction?

1 Answer 1

2

You could create a variable before including your widget script.

<script type="text/javascript">var profileLink = "myprofilelink.html";</script>
<script type="text/javascript" src="widget.js"></script>

Then you can just use the variable in your widget.js file:

document.write("<a href=\"" + profileLink + "\">Click To View</a>");

If you want to learn about how to work with more advanced JavaScript widgets I'd recommend reading Developing An Embeddable Javascript Widget.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, just what I was looking for. Thanks for the further reading as well :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.