471,073 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Select SOME text from a page and use it as a var

If I open a new page with very little text on it such as
a bugmenot
results page
is there a way to select some of the text there and
assign it to variables?
Selecting all and copying to the clipboard can be done with:
document.execCommand("SelectAll");
document.execCommand("Copy");
but I'm looking for something a little more refined.

The page contains seven lines of text and I'd like a simple way to say:
var username = [contents of line 4]
var password = [contents of line 5]
Can anyone point me in the right direction?

Jul 23 '05 #1
4 1545
On 16 Dec 2004 06:31:44 -0800, melvynadam wrote:
If I open a new page with very little text on it such as
a bugmenot
results page
is there a way to select some of the text there and
assign it to variables?


on the fly:

function getCurrentSelection(){
if (window.getSelection)
return typeof window.getSelection().toString();
else if (document.getSelection)
return document.getSelection()
else if (document.selection && document.selection.createRange)
return document.selection.createRange().text;
else
return null;
}

var sel=getCurrentSelection();

maybe it could be help you.

--
ZER0

~ The Tangent Universe collapsed 5891 days, 9 hours, 2 minutes and 6 seconds ago.

on air ~ "(Unknown Artist) - The Artifact And Living"
Jul 23 '05 #2
Thanks for the incredibly quick response! Unfortunately it's not quite
what I'm looking for - I want the process to be automated. If I have to
manually select the text it negates the point of the plugin I'm trying
to create.
I wish to open a bugmenot results page using my current location (e.g.
www.nytimes.com) with this line:
window.open('http://www.bugmenot.com/view.php?mode=bookmarklet&url='+document.location, 'click','height=300,width=400,title=no,location=no ,scrollbars=yes,menubars=no,toolbars=no,resizable= yes');
Then, in the new window I wish to automatically select the only text on
that page which changes (take a look at
http://www.bugmenot.com/view.php?mod...ww.nytimes.com
if you copy and paste all of the text you'll see that it's nicely
formatted and the two desired fields are on their own on individual
lines).
Later I'll want to try to return to the original page and find the
fields "user" or "username" etc. and paste back my results.

Jul 23 '05 #3
On 16 Dec 2004 07:01:12 -0800, melvynadam wrote:
I wish to open a bugmenot results page using my current location (e.g.
www.nytimes.com) with this line:
window.open('http://www.bugmenot.com/view.php?mode=bookmarklet&url='+document.location, 'click','height=300,width=400,title=no,location=no ,scrollbars=yes,menubars=no,toolbars=no,resizable= yes');
Then, in the new window I wish to automatically select the only text on
that page which changes (take a look at
http://www.bugmenot.com/view.php?mod...ww.nytimes.com


Wait, let me understand (I'm sorry, but my english is not very good)..

You have a page in a domain (http://www.nytimes.com); and you want open a
popup that points in other domain (http://www.bugmenot.com/), and after get
some information from this?

In according with SOP (Same Origin Policy), you cannot do it:

http://www.mozilla.org/projects/secu...me-origin.html

--
ZER0

~ The Tangent Universe collapsed 5891 days, 9 hours, 26 minutes and 52 seconds ago.

on air ~ "donny darko - Mad World (full version)"
Jul 23 '05 #4
"melvynadam" <me*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
If I open a new page with very little text on it such as
a bugmenot
results page
is there a way to select some of the text there and
assign it to variables?
Selecting all and copying to the clipboard can be done with:
document.execCommand("SelectAll");
document.execCommand("Copy");
but I'm looking for something a little more refined.

The page contains seven lines of text and I'd like a simple way to say:
var username = [contents of line 4]
var password = [contents of line 5]
Can anyone point me in the right direction?


Will this help? Watch for word-wrap.

<html>
<head>
<title>bugmenot.htm</title>
<script type="text/javascript">
function bugmenot() {
var sWWW = http://www.bugmenot.com/view.php?url=;
var sURL = document.getElementById("URL").value;
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sWWW+sURL,false);
oXML.send();
try {
var sXML = oXML.ResponseText;
var iDD1 = sXML.indexOf("<dd>");
var iDD2 = sXML.indexOf("</dd>");
var sVAL = sXML.substr(iDD1+4,iDD2-iDD1-4);
var sUSR = sVAL.substr(0,sVAL.indexOf("<"));
var sPWD = sVAL.substr(sVAL.indexOf(">")+1);
document.getElementById("USR").value = sUSR;
document.getElementById("PWD").value = sPWD;
document.all.i.src = sWWW+sURL;
} catch(e) {
alert(sWWW + sURL + " Failed!");
}
}
</script>
</head>
<body>
<center>
<form>
<table border="0" width="600">
<td align="center">
<b>Enter a URL: </b>
<input type="text" name="URL" id="URL" size="30"
value="www.nytimes.com">
&nbsp;
<input type="button" value="Bug Me Not!" onclick="bugmenot()">
</td>
<tr>
</tr>
<td align="center">
<b>Username: </b>
<input type="text" name="USR" id="USR" readonly>
&nbsp;
<b>Password: </b>
<input type="text" name="PWD" id="PWD" readonly>
</td>
</tr>
</table>
</form>
<iframe name="i" align="center"
frameborder="1" scrolling="no"
marginwidth="0" marginheight="0"
style="width:600; height: 380"></iframe>
</body>
</html>
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by JT | last post: by
4 posts views Thread by point | last post: by
6 posts views Thread by Chris Fink | last post: by
3 posts views Thread by mark.irwin | last post: by
13 posts views Thread by PinkBishop | last post: by
4 posts views Thread by rn5a | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.