Reputation: 12568
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?
Upvotes: 1
Views: 193
Reputation: 4399
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.
Upvotes: 2