Skip to content
Advertisement

Parse and add url from clipboard

I need a javascript bookmark to take the url I have in the clipboard parse out the 2 numbers and create a new url, and add a link to the top of the page, that when clicked adds the url to my bookmark menu.

Say I have url’s like these

http://www.website.com/frontpageeditor.jhtml?sectionID=2844&poolID=6276
javascript:getPoolPageUrl(9800,22713)

Then I need to add the numbers to this url

javascript:frames['content'].getPoolPageUrl(9800,22713)

and then add the url to the top of the frame “content”.

I have tried forever on this, but I can’t figure out it out.



Update
I’ve put something together, to show you what I need. This one doesn’t work though.

Any ideas why?

var url = window.clipboardData.getData('Text');
var reg = /(d+)/g;
var matches = url.match(reg); //returns ["2844","6276"]
var newUrl = "javascript:frames['content'].getPoolPageUrl("+matches[0]+","+matches[1]+")";
var link = document.createElement('a');
link.src = newUrl;
frames['content'].document.body.appendChild(link);



Update2
This works. Any changes I can do to make it even better?

var url = window.clipboardData.getData('text');
var matches = url.match(/(d+)/g);
var link = frames['content'].document.createElement('a');
link.href = "javascript:frames['content'].getPoolPageUrl("+matches[0]+","+matches[1]+")";
link.innerHTML = document.title;
frames['content'].document.body.appendChild(link);

Advertisement

Answer

Ok, first of all I think you cannot retrieve the text from clipboard from java script, my guess that it would be a major security issue if you can.

Let’s assume you have the clipboard in a string you can call this function:

var url = "http://www.website.com/frontpageeditor.jhtml?sectionID=2844&poolID=6276"; //clip
var reg = /(d+)/g;
var matches = url.match(reg); //returns ["2844","6276"]
var newUrl = "javascript:frames['content'].getPoolPageUrl("+matches[0]+","+matches[1]+")";
frames['content'].document.getElementById("linkPlaceHolderWhereYouWantToAdd").href=newUrl;
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement